Posted: Mon Mar 03, 2008 12:10 am Post subject: Using data from two tables, help with join statement?
I've been trying many combinations of things, but I think what I need is some kind of join statement. I have two tables, xyz_dest and xyz_destloc. I'm performing a query that needs to find all of the rows in xyz_destloc that have a specific zipcode column but also checks to see if the 'title' column of xyz_dest is similar to the search term.
The method I'm trying to accomplish is to perform that search, but then only display DISTINCT rows from xyz_dest that show all of the rows from xyz_destloc that are relevant.
For example
xyz_dest:
id | title
1 | 'Destination 1'
2 | 'Destination 2'
3 | 'Destination 3'
So if I search for a title similar to 'destination' in the zipcode 12345, I would like it to return:
"Destination 1: 123 way & 412 street"
I hope that makes sense
Right now, my query is something like this - that does not function...
"SELECT xyz_dest.id, xyz_dest.title FROM xyz_dest, xyz_destloc ON xyz_destloc.destid=xyz_dest.id WHERE xyz_destloc.zipcode='$zipcode' AND xyz_dest.title LIKE '%$keywords%'"
Joined: 02 May 2004 Posts: 6033 Location: toronto, canada
Posted: Sat Mar 08, 2008 4:06 am Post subject:
SELECT xyz_dest.id, xyz_dest.title, xyz_destloc.address
FROM xyz_dest INNER JOIN xyz_destloc
ON xyz_destloc.destid=xyz_dest.id
WHERE xyz_destloc.zipcode='$zipcode'
AND xyz_dest.title LIKE '%$keywords%'
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum