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 (....)?

有帮助吗?

解决方案

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
)

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top