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

Hard to explain SELECT question 1

Status
Not open for further replies.

markj11

Programmer
Mar 24, 2006
11
US
TableA A B
1 X
1 Y
2 X

I want my results to be 1 X because B = Y.

This is kind of what I was tring:
Code:
SELECT	DISTINCT A,
	CASE 	WHEN B = 'X' THEN
		   B
		ELSE
		   ''
		END
	AS B
FROM
	tableA
WHERE
	B = 'Y'
 
Maybe.......
Code:
SELECT DrvA.A, DrvA.B
FROM (SELECT A,B
      FROM TableA
      WHERE B = 'Y') DrvA
WHERE DrvA.B <> 'Y'
-SQLBill

Posting advice: FAQ481-4875
 
Maybe...
Code:
SELECT TblA.A, TblA.B
FROM TableA TblA
 LEFT OUTER JOIN (SELECT A
                  FROM TableA
                  WHERE B = 'Y') TblB
   ON TblA.A = TblB.A
WHERE TblA.B <> 'Y'

-SQLBill

Posting advice: FAQ481-4875
 
Thank you. That would work great but I just realized the table is like this
A B C
1 X AA
1 Y BB
2 X AA

and I want 1 BB because B = X
 
Thanks, A varaition of the last SQL will do just fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top