Salman Quader Salman Quader - 7 months ago 16
SQL Question

i have tow table which contain on same column like UserID. How to get all row by subquery

i have tow table which contain on same column like UserID


1. employee
--------------------------------------------------------
id UserID Name Description
1 username1 fullName1 employee Description1
2 username2 fullName2 employee Description2
--------------------------------------------------------

2. user_info
--------------------------------------------------------
id UserID password
1 username1 password1
2 username2 password2

--------------------------------------------------------


I have user_info data. I want to employee table row according to user_info data By "Subquery"
just i want to use subquery syntax

Answer

I don't know why do you just want a subquery, but try this, maybe works;)

select e.*
from employee e
where exists (
    select 1 from user_info u
    where e.UserID = u.UserID
)
-- maybe some conditions else need, you can add it by yourself

Or you also can try this,

select e.*
from employee e
where e.UserID in (
    select u.UseID from user_info u
)

Anyway, perhaps other solution exists...