Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join Query Problem...

Status
Not open for further replies.

handle87

Programmer
Jun 27, 2005
53
0
0
CA
Hi,

I am having a problem writing a join query....

What I want to get is all the records from Table1 and join it to Table2... if there is no matching record in Table2 I would like to see NULL values in the fields... I thought it would be a LEFT JOIN but does not seem to work...

Here is one of the ideas that I tried:

Code:
SELECT
  Table1.*,
  Table2.*
FROM
  Table1 AS a
LEFT JOIN
  Table2 AS b
ON
  a.Field1 = b. Field1

I need all rows from Table1 wether there is a matching record in Table2 or not....

Any ideas?

CES
 
Your query looks fine, except that, since you have aliased the tables, you should be selecting a.* and b.* . Is that the only problem?
 
Thanks... it was a a logic problem... needed to add another ON clause to the query... one of those silly mistakes that cost u more time than it should... Thanks for lookin at it!

CES
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top