Saturday, January 10, 2009
MySQL LEFT JOIN
Keywords: MySQL, MySQL Query, MySQL LEFT JOIN, MySQL JOIN
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:
- MySQL SQL_CACHE - http://kathyravan.blogspot.com/2008/12/mysql-sqlcache.html
- MySQL Query Caching - http://kathyravan.blogspot.com/2008/12/mysql-query-cache.html
- MySQL Show - http://kathyravan.blogspot.com/2008/12/mysql-show-statements.html
- CSV - MySQL Storage Engine - http://kathyravan.blogspot.com/2008/12/csv-mysql-storage-engine.html
- Blackhole - MySQL Storage Engine - http://kathyravan.blogspot.com/2008/12/blackhole-mysql-storage-engine.html
- Memory - MySQL Storage Engine (Formerly Heap Storage Engine) - http://kathyravan.blogspot.com/2008/12/memory-mysql-storage-engine-formerly.html
- Xml in MySQL - http://kathyravan.blogspot.com/2008/03/xml-in-mysql.html
- Forgot mySQL root Password? - http://kathyravan.blogspot.com/2008/02/forgot-mysql-root-password.html
- Samba - Installation & Configuration - http://kathyravan.blogspot.com/2008/02/samba-installation-configuration.html
- Enabling HTTP Authentication in Apache - http://kathyravan.blogspot.com/2008/08/enabling-http-authentication-in-apache.html
- PHP Function: isFTPFileExists (Searching a FILE in FTP) - http://kathyravan.blogspot.com/2008/12/php-function-isftpfileexists-searching.html
- Shell Scripting & Linux - http://kathyravan.blogspot.com/search/label/Shell%20Scripts
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment