Jump to content

Archived

This topic is now archived and is closed to further replies.

Thierry

Empty field, query cant find

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.field1
FROM table2 t2 LEFT JOIN table1 t1 ON t2.field1 = t2.field1
ORDER BY t2.field2[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.