Anthony R
Anthony R

Reputation: 88

Mysql query that ONLY shows individual results from column

I have two tables. The main table holds a list of ids, the other has a list of ids that are duplicates and need to be removed from the main table. The Distinct constraint isn't really helpful, to my knowledge at least, and I am not sure what is the best way to get the needed results. Any and all help is appreciated (sql queries are NOT my strong point, and I have searched for a good bit trying to figure this out)

Upvotes: 0

Views: 23

Answers (1)

Marcus Adams
Marcus Adams

Reputation: 53830

It seems like you want to list records in one table where the values don't exist in another table.

You can do it various ways.

With NOT IN and a subquery:

SELECT * FROM table1
WHERE id NOT IN (SELECT id FROM table2)

With an anti-join:

SELECT t1.* FROM table1 t1
LEFT JOIN table2 t2
  ON t1.id = t2.id
WHERE t2.id IS NULL

Upvotes: 2

Related Questions