I want to show data where data is not in other tables.
Asked
Active
Viewed 245 times
-1
-
Can you share the code that you used so far? – Ende Jun 04 '18 at 14:26
-
2Possible duplicate of [SQL - find records from one table which don't exist in another](https://stackoverflow.com/questions/367863/sql-find-records-from-one-table-which-dont-exist-in-another) – Masivuye Cokile Jun 04 '18 at 14:27
-
See: [Why should I provide an MCVE for what seems to me to be a very simple SQL query?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query) – Strawberry Jun 04 '18 at 14:28
-
This is not a PHP, nor mysqli question. Look at `join`s with `mysql`. – user3783243 Jun 04 '18 at 14:28
1 Answers
-1
Use a sub query.
SELECT a.*
FROM tabel_a a
WHERE a.id NOT IN (SELECT b.id FROM tabel_b b)
Output
id name
1 aa
2 bb
SQL Fiddle: http://sqlfiddle.com/#!9/8d5a32/6/0

Matt
- 14,906
- 27
- 99
- 149
-
Better is to use `a LEFT JOIN b ... WHERE b.column IS NULL` @A.Colonna Because `NOT EXISTS` requires a co-related subquery.. – Raymond Nijland Jun 04 '18 at 15:24
-