Hey everyone, I have 2 tables: phones - This table stores basic information about an individual handset (make, model, imei etc...). additionalInfo - This table stores further information like shape. Example tables: phones id make model imei 1 Nokia 3310 12345 2 Apple iPhone 3GS 54321 3 Apple iPhone 3GS 33333 Code (markup): additionalInfo id listingID shape 7 1 Block 8 2 Block 9 3 Block Code (markup): How would I go about making a query that searches for records from the phones table where it matches the make and model, and then ensures the match also has the right form of shape? Just to clarify, what I require IF it were a single table like this: Hypothetical Merged Table id make model imei shape 1 Nokia 3310 12345 Block 2 Apple iPhone 3GS 54321 Block 3 Apple iPhone 3GS 33333 Block Code (markup): What I would need is: SELECT * FROM `thisTable` WHERE `make` = '$make' AND `model` = '$model' AND `shape` = '$shape' Code (markup): Thanks in advance!
Hello, Following is the answer of your question: If you want to select all records SELECT * FROM phone, additionalInfo WHERE phone.id = additionalInfo.listingID; If you want to select a particular record SELECT * FROM phone, additionalInfo WHERE phone.id = 1 AND additionalInfo.listingID = 1; Thanks, Jimmy
Ahhh that's the one! I learnt it ages ago when I first learned MySQL and I haven't used it since then so I forgot! Anyway thanks a lot, very helpful. Rep added!