Solved

SQL where NOT DISTICNT

Posted on 2004-03-29
2
269 Views
Last Modified: 2009-07-29
I have a shipping table with order number called FDDOCO. I need to select only orders which have 2 or more FDDOCO. what this mean is that each order is usually represented once in shipping, but sometimes orders are split up and shipped in 2 or 3 seperate shipments with the same FDDOCO num. any ideas???
0
Comment
Question by:timokeeffe
2 Comments
 
LVL 15

Expert Comment

by:SRigney
Comment Utility
-- select the distinct FDDOCO numbers that are in tblShipping more than once.
SELECT FDDOCO from tblShipping
group by FDDOCO
having count(FDDOCO) > 1

If you then want to select all orders that have an FDDOCO number that is duplicated then you would use a subselect
select * from tblShipping
inner join
(
SELECT FDDOCO from tblShipping
group by FDDOCO
having count(FDDOCO) > 1
) as tmp
on tblShipping.FDDOCO = tmp.FDDOCO
0
 
LVL 3

Accepted Solution

by:
debi_mela earned 500 total points
Comment Utility

--to list all orders with orderno = FDDOCO, and occurs more than once..

select * from tblshipping where orderno in
(SELECT distinct orderno from tblShipping where orderno = 'FDDOCO'
group by orderno  having count(orderno) > 1
)


-- In general for any orderno..

select * from tblshipping where orderno in
(SELECT distinct orderno from tblShipping
group by orderno  having count(orderno) > 1
)
 
 
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now