A
A
Anton2016-08-17 00:55:22
PostgreSQL
Anton, 2016-08-17 00:55:22

How to get the records of the first table that have no links in the records of the second table?

There are two tables - posts and covers.
The covers has a "post_id" field.
How to get posts that don't have covers?
Tried to do something using JOIN, but didn't work...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2016-08-17
@hummingbird

SELECT `p`.`id`
  FROM `posts` AS `p`
  LEFT JOIN `covers` AS `c` ON `c`.`post_id` = `p`.`id`
  WHERE `c`.`post_id` IS NULL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question