0

I have 2 tables:

table1 (id,usedcode)
table2 (codeid,uniquecode)

I want to be able to check if a certain value exists in uniquecode of Table2, but is not already used in Table1

Strawberry
  • 33,750
  • 13
  • 40
  • 57

2 Answers2

1

Try using left join as below:

SELECT t2.*
FROM table2 t2 LEFT JOIN table1 t1
ON t2.uniquecode = t1.usedcode
WHERE t1.usedcode IS null
SMA
  • 36,381
  • 8
  • 49
  • 73
0
SELECT uniquecode FROM Table2
WHERE NOT EXISTS( 
    SELECT * FROM Table1 WHERE usedcode = uniquecode
)

In English the query is saying, "Select all unique codes from table 2 that don't exist in table 1 as a usedcode".

Kacy
  • 3,330
  • 4
  • 29
  • 57