Jump to content
whosmer

SQL query for values that are both available and null

Recommended Posts

I have a table (Table1) where one of the columns is the ID (Table2ID) for a second table (Table2).

I know how to query Table1 and get all of the values, my issue is to be able to return the corresponding Name from table 2. I'm stumbling over NULL and available ID.

image.png.248cebca395019986c6442c306827a6b.png

Any assistance would be appreciated.

Thanks!

Share this post


Link to post
Share on other sites

You can LEFT JOIN the tables. Of course, wherever there's a NULL, all you'll get is NULL for the fields in table 2. If you want to completely ignore NULL rows, a plain JOIN will do that.

Share this post


Link to post
Share on other sites

If you want to show null value then you have to try this query :

select  t1.table1id,  t1.table2id,  t2.table2name  from  table1 t1  left join  table2 t2  on  t1.table2id  =  t2.table2id ;

 

If you do not want to show that null values then use this query :

select  t1.table1id,  t1.table2id,  t2.table2name  from  table1 t1  inner join  table2 t2  on  t1.table2id  =  t2.table2id ;

 

I hope this will show you your desired answer. let me know if you do this.

Share this post


Link to post
Share on other sites

That's exactly what I said.

Share this post


Link to post
Share on other sites

Haven't you noticed? That's all they do! Shah twins and now sherin too. They copy the solutions from previous posters, none of them have contributed a solution to the forum by themselves.

Share this post


Link to post
Share on other sites

I have been aware, yes.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...