Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question