Click here to Skip to main content
15,915,172 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
id - name - sub_id
4 | a | 5
5 | b | 4
6 | d | 4
7 | c | 4
8 | e | 7
9 | f | 4
10 | g | 7
Posted
Updated 4-Jun-14 2:43am
v2
Comments
Member 10285877 4-Jun-14 8:45am    
sir its only return id 4 but i need id 4 and its related id for eg: 7 and its subid also need

try this.. :)

SQL
select e1.id,e1.name,e2.name as Name2 from tableName e1 inner join tableName e2 on e1.subid=e2.id
 
Share this answer
 
Comments
Member 10285877 4-Jun-14 8:52am    
thanks sir its work for me
Nirav Prabtani 4-Jun-14 9:04am    
welcome.. :)
SELECT name from test_test where id = 4
union
SELECT name from test_test where sub_id = 4

also



SELECT name from test_test where id in (
SELECT id from test_test where sub_id in (4) or id in (4)
)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900