Question

I have these 2 tables.

Table una:

| id | word | desc |

Table match:

| id | word | review |

Table una has several thousands rows, table match will eventually have the same size as una but currently has very only a few rows.

What I want is to SELECT all rows from una, BUT, don't show rows that have a word that also exist in match AND are set as review = 0.

Do I need to use IF EXISTS (....)?

Was it helpful?

Solution

You will want SQL along this line of:

SELECT * FROM una WHERE word IN (
  SELECT word FROM una
  MINUS
  SELECT word FROM match WHERE review = 0
)

Update: improved:

SELECT * 
FROM una 
WHERE word NOT IN (
  SELECT word 
  FROM match 
  WHERE review = 0
)

OTHER TIPS

select u.*
from una u
     left join match m on u.word=m.word
having m.word is null
SELECT *
FROM una AS u
WHERE u.word NOT IN (SELECT word FROM match)
AND u.review = 0

EDIT - Sorry this is for TSQL, I don't know if its the same for Mysql.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top