I'm going daft. I have what should be a simple query and it seems that
the left side of the join is being ignored. The query and DDL are
below. Basically, my RDOData_Extract_Lines table (where LineNum NOT
LIKE 'LAN%') on it's own gives me 959 records. If I look at the
RDOData_Extract table (with the dealer code = 8494) it shows 521
records. Using the query below and specifically a left join it 'should'
show me 959 records, but only show data for 521 of them. However, it
shows me 521 records. What have I done wrong ?
Thanks
Ryan
SELECT
L.LineDesc,
D.*
FROM
RDOData_Extract_Lines L
LEFT JOIN RDOData_Extract D
ON L.LineNum = D.Line_No
WHERE
L.LineNum NOT LIKE 'LAN%' AND
D.Dealer_Code = 8494
CREATE TABLE [RDOData_Extract] (
[Dealer_Code] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[FranDealerCode] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[Line_No] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Current] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[YTD] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[12Months] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[24Months] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Average_YTD] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[Average12months] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[Average24Months] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[Last_YTD] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Current_Status] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[PD1] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD2] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD3] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD4] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD5] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD6] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD7] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD8] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD9] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD10] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD11] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD12] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD13] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD14] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD15] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD16] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD17] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD18] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD19] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD20] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD21] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD22] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD23] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD24] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD25] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD26] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD27] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD28] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD29] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD30] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD31] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD32] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD33] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD34] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD35] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PD36] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[SortOrder] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [RDOData_Extract_Lines] (
[DeptId] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[DeptDesc] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[LineNum] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[LineDesc] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[SortOrder1] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[SortOrder2] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO 2 6373
Ryan (ry********@hotmail.com) writes: SELECT L.LineDesc, D.*
FROM RDOData_Extract_Lines L LEFT JOIN RDOData_Extract D ON L.LineNum = D.Line_No
WHERE L.LineNum NOT LIKE 'LAN%' AND D.Dealer_Code = 8494
This how it works: first you have a table specified with FROM. Then you
get a new table (conceptually) by with JOIN. When you use a LEFT JOIN
all rows in the left tables are included, and the columns from the
right table as NULL.
Then you apply a WHERE clause on this table and filter rows with the
conditions you have. With the condition on D.Dealer_code, all rows
with NULL goes out the window.
This gives a coupld of ways to fix this. The most common and probably the
best is to move the condition on Dealer_code to the ON part.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Cool. Knew I'd missed something simple. Just having a bad day. Thanks ! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: StealthBananaT |
last post by:
My database has two tables - films has 10,000 records and reviews has 20,000 records. Whenever I try to list all the films and the
count of its reviews, MySQL locks and I have to restart the...
|
by: Marek Lewczuk |
last post by:
Hello,
I have a strange problem, maybe some of you will be able to explain me
something. I use LEFT JOIN as a substitute for subselects. It's true
that many subselects can be rewriten using LEFT...
|
by: Marek Kotowski |
last post by:
In MySQL online documentation there are some examples with
multi-tables left joins. But all of them are like this (taken from the
documentation):
SELECT ...
FROM table1
LEFT JOIN table2 on...
|
by: Eric |
last post by:
Hi Folks,
Lets assume I have three tables. Their layout is as follows. Please
note that tblPeople does not have an entry for Denver (this is my
problem)
tblCity
_________________
CityName ...
|
by: Quarco |
last post by:
Hi,
Suppose I have a query like:
SELECT
products.name AS product,
SUM(IF(stock.invoice=0,1,0)) AS in_stock,
SUM(IF(shopcart.status=1,1,0)) AS reserved
FROM products
LEFT JOIN stock ON...
|
by: Dam |
last post by:
Using SqlServer :
Query 1 :
SELECT def.lID as IdDefinition,
TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour
FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
|
by: Steve |
last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three
"Left Outer Joins" in order to return every transaction for a specific
set of criteria.
Using three "Left Outer Joins"...
|
by: deko |
last post by:
SELECT tblTxAcct.TxAcctName, tblTxType.TxTypeName,
Nz(qryTxAcctListCt.TxCount, 0) AS TxCt
FROM (tblTxAcct INNER JOIN tblTxType ON
tblTxAcct.TxType_ID=tblTxType.TxType_ID) LEFT JOIN qryTxAcctListCt...
|
by: Doug |
last post by:
Hi,
I'm more familiar with MSSQL than Access syntax and have run into a problem
with correctly putting ( )'s around the joins in a 3 table query. I want to
INNER JOIN lenders and accounts and...
|
by: shapper |
last post by:
Hello,
I am used to SQL but I am starting to use LINQ.
How can I create Left, Right and Inner joins in LINQ? How to
distinguish the different joins?
Here is a great SQL example:...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |