An Entrepreneur, Coach, IT Consultant, Strategic Adviser, and a Traveler craving to explore and contribute to forming a better society.

Saturday, January 10, 2009

MySQL LEFT JOIN

No comments :
Keywords: MySQL, MySQL Query, MySQL LEFT JOIN, MySQL JOIN

Question
: I've got the following table (BANK)


ID

Name

Manager

A

Person 1

-

B

Person 2

A

C

Person 3

A

D

Person 4

B

E

Person 5

B

F

Person 6

C

G

Person 7

C


I'd like to have a query which prints Name, Manager of each person. Something like the following output


Name

Manager

Person 1

-

Person 2

Person 1

Person 3

Person 1

Person 4

Person 2

Person 5

Person 2

Person 6

Person 3

Person 7

Person 3


Answer:

You can do it with LEFT JOIN option.

Pls refer the following statement:

mysql> select a.name as Name, b.name as Manager from bank a LEFT JOIN bank b on b.id=a.manager;

Keywords: MySQL, MySQL Query, MySQL LEFT JOIN, MySQL JOIN

Featured Blog Topics:

No comments :