473,461 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Left join in table with subqueries

select pkrreview.DK_Number,pkrreview.BindingType,pkrrevie w.Category,pkcustomerorder.CONo
from
(select distinct p.category 'Category',t.bindingtype 'BindingType',p.dknumber 'DK_Number',
p.AddDate 'ReviewDate',t.title 'Title',t.titleid 'TitleId',cq.quantityOrdered 'QtyOrdered',
cq.customerOrderNO 'OrderNo',cq.customerOrderDate 'OrderDate',cq.CODKdate,cq.InvoiceNo,
co.billtoid 'BilledId' from title t,dkpub1.dbo.TitleReview p(Nolock),
COQuantityDetails cq(NOLOCK),customerorder co(NOLOCK),InvoicesEntry IE (NOLOCK)
Where t.category=p.category and t.dknumber=p.dknumber and co.coid=cq.coid and
ie.billedto=co.billtoid and cq.titleid=t.titleid and p.AddDate >'2005-12-31'
and p.AddDate < '2007-01-31')as pkrreview
left join
(SELECT count(co.CONo) 'Qty of Order No',t.DKNumber 'DKN0',ct.Description 'DKCategory',bm.Description 'DKBindingType',
co.CONo
FROM CustomerOrder co(NOLOCK),COQuantityDetails cq(NOLOCK), Title t(NOLOCK),
BindingTypeMaster bm(NOLOCK),CategoryMaster ct(NOLOCK),ProcessTypeMaster pt(NOLOCK),
CustomerMaster c1(NOLOCK),CustomerMaster c2(NOLOCK), MonthMaster mm(NOLOCK),
(select distinct p.category 'Category',t.bindingtype 'BindingType',p.dknumber 'DK_Number',
p.AddDate 'ReviewDate',t.title 'Title',t.titleid 'TitleId',cq.quantityOrdered 'QtyOrdered',
cq.customerOrderNO 'OrderNo',cq.customerOrderDate 'OrderDate',cq.CODKdate,cq.InvoiceNo,
co.billtoid 'BilledId'
from title t,dkpub1.dbo.TitleReview p(Nolock),COQuantityDetails cq(NOLOCK),
customerorder co(NOLOCK),InvoicesEntry IE (NOLOCK)
Where t.category=p.category and t.dknumber=p.dknumber and co.coid=cq.coid and
ie.billedto=co.billtoid and cq.titleid=t.titleid and p.AddDate >'2005-12-31' and
p.AddDate < '2007-01-31')pkr
WHERE co.COId = cq.COId AND cq.TitleId = t.TitleId AND t.Category = ct.Code AND t.BindingType = bm.Code
AND co.BillToId = c1.CustomerId AND co.ShipToId = c2.CustomerId AND co.Month = mm.Code
AND ct.code = pkr.category AND t.DKNumber = pkr.DK_Number AND bm.code = pkr.BindingType
AND co.ProcessTypeCode *= pt.Code
group by t.DKNumber,ct.Description,bm.Description, co.CONo)pkcustomerorder
on pkrreview.DK_Number=pkcustomerorder.DKN0
Apr 9 '10 #1
0 1220

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
0
by: Soefara | last post by:
Dear Sirs, I am experiencing strange results when trying to optimize a LEFT JOIN on 3 tables using MySQL. Given 3 tables A, B, C such as the following: create table A ( uniqueId int not...
11
by: news-east.earthlink.net | last post by:
The scenario: two tables CustomerTable --------------- CustomerID OrderID CustomerName CustomerEmail
1
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...
23
by: Brian | last post by:
Hello All - I am wondering if anyone has any thoughts on which is better from a performance perspective: a nested Select statement or an Inner Join. For example, I could do either of the...
3
by: media.opslag | last post by:
Hi, How can i get this to work in access / jet sql ??? Someone?? SELECT tbl1., tbl2. FROM tbl1 left outer join tbl2 on
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
6
by: Avaenuha | last post by:
I need to use a left outer join to get all of one table, and match it to specific instances of another table. Eg, report all of A, and where A has made a specific kind of B, report the name of that...
5
by: Sascha.Moellering | last post by:
Hi, I receive the error code SQL0338N if I try to compile this statement (part of the statement): .... left outer join lateral (SELECT * FROM LIZSYSABA.VWZL0359TBS WHERE tbs_name = CASE WHEN...
4
by: polycom | last post by:
Assistance needed to optimize this query SELECT SD.content_id AS Id, SD.title AS Title, CT.name AS Contenttype, PV.content_id AS SponsorId, ...
1
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...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.