M
M
Maxim Cherepantsev2016-11-16 17:54:04
Python
Maxim Cherepantsev, 2016-11-16 17:54:04

How to get data that is not related to another table?

Hello.
There are two tables. Conditionally - User and Articles.
Articles has a user_id field. It contains the id of the record from the User table. Well, I think it's clear.
I need to get all User records that are not mentioned in the Articles table. Those. all User records whose IDs are NOT listed in any Articles record.
I hope I explained clearly. Can this be done using SQL? Or SQLAlchemy? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2016-11-16
@RevHarris

You need a LEFT OUTER JOIN

select u.name from users as u
left join articles as a on u.id = a.user_id
where a.id is null;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question