Query
Query
(OP)
Hi,
I have the following result from a select statement:
Column: A B C
Data : 55 S 123
Data : 55 T 123
Data : 09 S 123
Data : 09 T 123
I am new to SQL and I cannot figure out a way to do the following: "If there are rows with same values in Column A, select the rows with 'T' in column B."
Your help is greatly appreciated. Thanks.
I have the following result from a select statement:
Column: A B C
Data : 55 S 123
Data : 55 T 123
Data : 09 S 123
Data : 09 T 123
I am new to SQL and I cannot figure out a way to do the following: "If there are rows with same values in Column A, select the rows with 'T' in column B."
Your help is greatly appreciated. Thanks.
RE: Query
SELECT A,B,C FROM yourTable WHERE B='T'
Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?
RE: Query
Column: A B C
Data : 55 S 123
Data : 55 T 123
Data : 55 Z 123
Data : 09 S 123
Data : 09 T 123
Data : 09 S 123
Just for clarification: I want to do is "if there are rows with same Column A value, select the last row."
RE: Query
What is your actual SQL code returning the above result ?
Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?
RE: Query
Column: A B C
Data : 55 S 123
Data : 55 T 123
Data : 55 Z 123
Data : 09 S 123
Data : 09 T 123
Data : 09 S 123
I sorted the result so what I want is "55 Z 123" and "09 S 123" out of the above table. I have created a view so the original statement does not matter I guess. Thanks a lot for your help.
RE: Query
Why isn't "09 T 123" the last result ?
Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?
RE: Query
RE: Query
CODE
, q.B
, q.C
FROM ( SELECT A
, MAX(D) AS latest
FROM queryresult
GROUP
BY A ) AS m
INNER
JOIN queryresult AS q
ON q.A = m.A
AND q.D = m.latest
r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
RE: Query
RE: Query