MYINFO
ID(PK)/CmpID(FK)/NAME/POSITION/PhoneNumber
0/1 / Hong Gil-dong 1 / Employee / 010-1234-5678
1/ 1 / Hong Gil-dong 2 / Temple / 010-1234-5678
2/2 / Hong Gil-dong 3 / Temple / 010-1234-5678
3/3 / Hong Gil-dong 4 / Temple / 010-1234-5678
4/3 / Hong Gil-dong 5 / Employee / 010-1234-5678
5/4 / Hong Gil-dong 6 / Employee / 010-1234-5678
6/5 / Hong Gil-dong 7 / Temple / 010-1234-5678
CMPINFO
ID(PK)/CmpName/OfficeName
1 / Gogoseon Co., Ltd. / Korea 1
2 / Gogoseon Co., Ltd. / Korea 2
3 / Gogoseon Co., Ltd. / Korea 3
4/Hanra Co., Ltd. / China 1
5 / Hanara / China 2
ex)Hong Gil-dong 4-ga finds all the employees of his company regardless of the office. = CmpName finds everyone who is "(Go Chosun Co., Ltd.)
Results
Hong Gil-dong 1
Hong Gil-dong 2
Hong Gil-dong 3
Hong Gil-dong 4
Hong Gil-dong 5
I have to JOIN, but I don't know what to do.<
database sql join
I think I can solve it easily with SubQuery rather than JOIN I wrote the query statement for the ex you suggested.
SELECT my.NAME
FROM MYINFO as my, CMPINFO as cmp
WHERE my.CmpID = cmp.ID AND
cmp.CmpName =
(SELECT cmp.CmpName
FROM MYINFO as my, CMPINFO as cmp
WHERE my.NAME="Hong Gil-dong 4" AND my.CmpID=cmp.ID)
© 2024 OneMinuteCode. All rights reserved.