02 Mar, 2007
LEFT JOIN and RIGHT JOIN in mysql
Web Development » PHP, Snippets, Web Development Blog » LEFT JOIN and RIGHT JOIN in mysql
Use LEFT JOIN when you want to return all rows from left table regardless of whether they have any associated rows on right table.
Use RIGHT JOIN when you want to return all rows from right table regardless of whether they have any associated rows on left table.
SELECT users.`firstname`, pets.`nickname` FROM `users` LEFT JOIN `pets` ON users.`id` = pets.`user`";
The above query will return all rows in users table regardless of whether they have any pets associated with them or not.
Technorati Tags: mysql, sql, join, left join, right join
Other similiar posts that you might be interested in:
- 15 tips on optimising MySQL databases and MySQL queries
- Backuping and restoring a single table using mysqldump
- Why are my subqueries slow?
- Links Love Series 2: MySQL server fine tuning and administrating
- Remove the first character in mysql
- eZ Publish extensions for Flickr and YouTube
- Connecting to mysql from command line (eg: PuTTY, ssh)







