Skip to content
Advertisement

Select records in one table and specific matching records from the other

I have three tables, two of which are relevant for this question. Users, Things, User_to_thing

Users

User_to_thing

I’m trying to create a query where I can select all the active users in the users table and have a column where I can see the status for “thing 3” from the User_to_thing table while also sorting results so that the nulls come at the end. So the result would be something like:

What I have so far for a query is the following:

What I’m getting as a result is the following:

I’m not sure how to limit it to just thing #3 while also getting a list of all active users. Any guidance would be appreciated.

Advertisement

Answer

It looks like the following should work for you, grouping to remove duplicates and ordering based on null

Based on your revised data, you can amend slightly

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement