Jump to content

Empty field, query cant find


Thierry

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?
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.