I have two tables, one table is called queuelist and the other is call info. In the queuelist table it just lists different IDs. I am trying to get the ‘clientID’ from that table and match it with the ‘ID’ in the other table that contains all of the info and display it back on the page. Here is how the tables look:
Table – queuelist
ID | clientID ------------- 1 | 589 2 | 254 3 | 486
Table – info
ID | Name | Phone -------------------- 256 | Bob | 5551231234 486 | Jack | 5551231234 589 | Jill | 5551231234
This is what they call joining tables, you should use a query like this:
SELECT i.ID, i.Name, i.Phone FROM `queuelist` AS q LEFT JOIN `info` AS i ON ( q.clientID = i.ID );
I’m using aliases for shorter notation in the above query (queuelist becomes q and info becomes i) and then set the join condition (the bit between the ON()) to be the clientID from the queuelist table should match the ID in the info table.
Also see http://dev.mysql.com/doc/refman/5.0/en/join.html for more details.
You need to use an inner join
select * from queuelist as ql inner join info as i on ql.clientID = i.ID
Though you might want to replace * with specific field names e.g
select ql.clientID, i.fieldname FROM....
Well, I see no difficulty in this using a JOIN.
SELECT * FROM queuelist JOIN info ON clientID = info.ID WHERE queuelist.ID = 2
“Where” would be another option.
SELECT Name, Phone FROM queuelist,info WHERE clientID = ID
Assuming you want only name and phone