Snippets v2

Languages
My Snippets

Select Data from Left Join Login or Register to Bookmark this snippet

Description SQL

Selects data from two tables, that are left joined so matching data doesn't have to exist in the 2nd table for the data of the 1st to be returned.

Normally when selecting data from two tables with a "table1.field=table2.field" means that both tables must have a valid record for the row to be returned.

Using this method resolves such problems.

The Code Download
  1. SELECT
  2.     a.*
  3. FROM
  4.     table1 a
  5. LEFT JOIN
  6.     table2 b
  7. ON
  8.     b.id=a.id
  9. GROUP BY
  10.     a.id
  11. ORDER BY
  12.     a.id
Credits Contact JC

Added by JC on 15th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment