Search code examples
sqlt-sqlsoql

How to check a specific string in List on a SQL Select statement?


I was wondering if its possible to add a condition like the code below in a select statement, and if it is, how should I do it ?

code that looks like these

SELECT first_name ,last_name FROM persons_table [condition: WHERE last_name is on exclusiveList]


Solution

  • if your exclusiveList is on another table you can do:

    SELECT first_name ,last_name FROM persons_table 
    WHERE last_name in (select lastName from exclusiveListTable)
    

    or even nicer: use join as a filter:

    select * from  -- or select A.* from
    (SELECT first_name ,last_name FROM persons_table) A
    inner join
    (select lastName from exclusiveListTable ) B
    on A.last_name = B.lastName