SQL : Query For Multiple Column Value Filter

Hi Guys,

If you want to apply multiple column value filter on the same table, you can use following SQL Query:

Lets consider the table structure and data as below:

Now, if you run the below query:

select DISTINCT t.user_id, fst.meta_value as First_Name , lst.meta_value as Last_Name
from test as t
inner join test as fst on fst.user_id = t.user_id
inner join test as lst on lst.user_id = t.user_id
inner join test as est on est.user_id = t.user_id
where fst.meta_key =’first_name’ and lst.meta_key =’last_name’ and est.meta_key =’empid’
order by t.user_id

You will get the below result:

That’s it! You are done.

Leave a Reply