How to show data according to a specific value
I have a table like this:
----------------------------------
f1. : f2
----------------------------------
sonu : monu
rakesh : sonu
vivek : monu
raju. : sonu
sonu : umesh
ramesh : sonu
-----------------------------------------
if we look at a specific sonu value then I want to get data like this ...
----------------
c1
------------------
monu
rakesh
raju
umesh
ramesh
---------------------
Please help ... thanks in advance .... I asked this question from mobile, so it might not be easy to understand, but please try me ...
+3
source to share
2 answers
An interesting problem. Probably the easiest way is union all
:
select f2
from table t
where f1 = 'sonu'
union all
select f1
from table t
where f2 = 'sonu';
This is not the most efficient method for a large table, but it will work fine - especially if you have indexes on each column.
+4
source to share