Thierry Posted August 28, 2006 Share Posted August 28, 2006 I got a table with some IDs in it, and using (example, field1 is an ID, field2 is a name)SELECT table1.field1, table1.field2 FROM table1, table2 WHERE table1.field1 = table2.field1 ORDER BY table2.field2, I can order by the name of records in table 2 while I only got the ID in table 1.That all works fine, but if the table1.field1 (ID) is empty (which it can be, its not the key) then, instead of simply showing no name, it doesnt retrieve the record.I need it to retrieve the record regardless of its contents, if its empty, it should show no name.Any ideas? Link to comment https://forums.phpfreaks.com/topic/18884-empty-field-query-cant-find/ Share on other sites More sharing options...
Barand Posted August 28, 2006 Share Posted August 28, 2006 use LEFT JOIN to retrieve recs from table2 regardless of match in table1. Where there is a match, table1 value is returned. If no match the table1 value is returned as NULL[code]SELECT t2.field2, t2.field1, t1.field1FROM table2 t2 LEFT JOIN table1 t1 ON t2.field1 = t2.field1ORDER BY t2.field2[/code] Link to comment https://forums.phpfreaks.com/topic/18884-empty-field-query-cant-find/#findComment-81536 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.