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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting only certain records

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
US
My query gives me the following output:

DOCUMENT# TYPE
123 ABC
123 DEF
123 GHI
123 POD
555 ABC
555 POD

I want my final query to look like this:

DOCUMENT# TYPE
123 ABC,DEF,GHI
123 POD
555 POD

In other words, I only want to display a record for a given
document# if it has all three types "ABC,DEF,GHI" in the query. If it has less than those three document types, I do not want to show it. On the other hand, I always want to show the type "POD".

Help B-)
 
Try this...

Select DocNo, Type
From table1
Where Type='POD'

Union

Select Distinct DocNo, a.Type + ', ' + b.Type + ', ' + c.Type
From table1 a
Inner Join table1 b On a.DocNo=b.DocNo
Inner Join table1 c On a.DocNo=c.DocNo
Where a.Type='ABC'
And b.Type='DEF'
And c.Type='GHI'

Order by 1 Terry

The reason why worry kills more people than work is that more people worry than work. - Robert Frost
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top