iceblox Posted January 13, 2008 Share Posted January 13, 2008 Hi Guys, I have a table join which works fine. The tables are as below; {Code Table} modid / ModelID 1 / 52 1 / 53 {models table} modid / modelname / Makename 1 / Nokia / 5310 {Deals Table} ModelID / MakeName/ ModelName 52 / Nokia / 5310 Red 53 / Nokia / 5310 Blue This is my query which isnt working.. $res = $db->sql_query("SELECT deals.MakeName, deals.ModelName, deals.ModelID, code.modelid FROM code INNER JOIN deals ON code.modelid = deals.ModelID WHERE deals.ModelID != code.modelid GROUP BY deals.ModelName ORDER BY deals.MakeName, deals.ModelName ASC"); What id like to do is only display ModelIDs which are not in the code table already.. if this makes sense? tried to sort it but not having any luck.. Cheers, Phil Quote Link to comment https://forums.phpfreaks.com/topic/85805-solved-table-join/ Share on other sites More sharing options...
Barand Posted January 13, 2008 Share Posted January 13, 2008 SELECT deals.MakeName, deals.ModelName, deals.ModelID FROM deals LEFT JOIN code ON code.modelid = deals.ModelID WHERE code.modelid IS NULL Quote Link to comment https://forums.phpfreaks.com/topic/85805-solved-table-join/#findComment-437917 Share on other sites More sharing options...
iceblox Posted January 13, 2008 Author Share Posted January 13, 2008 Wicked , Thanks Barand Works a treat! Quote Link to comment https://forums.phpfreaks.com/topic/85805-solved-table-join/#findComment-437919 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.