2

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]

JF-Mechs
  • 1,083
  • 10
  • 23
  • How would one know if the person is on the exclusiveList to begin with? Is it stored in a separate table? In memory? A field in the user itself? – Joachim Isaksson Apr 04 '16 at 05:57
  • it could be on a separate table, but I am thinking to put them on a map or list which I could access in the select statement. – JF-Mechs Apr 04 '16 at 06:04

4 Answers4

3

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
Zahiro Mor
  • 1,708
  • 1
  • 16
  • 30
  • 1
    thanks, I was almost thinking the same code in your first example . Glad you wrote the right code! Also, thanks for the new idea on the second example have to read about the use of join before trying that one :) – JF-Mechs Apr 04 '16 at 06:15
  • yes you were almost there:) if it helped you - please consider accepting the answer – Zahiro Mor Apr 04 '16 at 06:17
0

It should be

SELECT first_name ,last_name FROM persons_table 
WHERE last_name in ('name1','name2',,,,'nameN')
Madhivanan
  • 13,470
  • 1
  • 24
  • 29
0
SELECT first_name ,last_name FROM persons_table 
WHERE last_name in (select name from table2)

OR

SELECT first_name ,last_name FROM persons_table 
WHERE Exists(select top 1 name from table2 where table2.columnname=persons_table.last_name)
Palanikumar
  • 6,940
  • 4
  • 40
  • 51
-1
SELECT * FROM TABLE_NAME WHERE REGEXP_LIKE(COLUMN_NAME,'REGEXP');
Panda
  • 6,955
  • 6
  • 40
  • 55
MITA
  • 1