Solved

SQL 2005 Left join

Posted on 2008-06-24
2
566 Views
Last Modified: 2010-05-18
I have a query that is similar to the one below.  I am trying to get all the records from tableA but the where clause is removing the records. I want the records that do not exists in the table b to be null.
select max(cola)
from tableA
left join tableB on tableB.colB = tableA.colB
where tableA.colA<table.colB
group by tableA.colA

Open in new window

0
Comment
Question by:yanci1179
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21855455
change:
select max(cola)
from tableA
left join tableB on tableB.colB = tableA.colB AND tableA.colA<table.colB
group by tableA.colA

Open in new window

0
 
LVL 43

Expert Comment

by:TimCottee
ID: 21855464
Hello yanci1179,

1:   select max(cola)
2:   from tableA
3:   left join tableB on tableB.colB = tableA.colB
4:   where tableA.colA<tableB.colB Or tableB.colB Is Null
5:   group by tableA.colA

Regards,

TimCottee
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question