Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
670 views
in Technique[技术] by (71.8m points)

SQL- Join Same Table with Filters

I have a single table (Tracker) containing 2 columns; (ID and Status). I would like to retrieve a list of ID's without the status approved, however a status can go from pending to approve and the original data will not be removed. See below example and desired outcome.

Tracker Table:

ID Status
123 Pending
123 Approved
456 Pending
678 Denied
894 Approved

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
SELECT T.ID,T.STATUS
FROM YOUR_TABLE AS T
WHERE NOT EXISTS
(
   SELECT 1 FROM YOUR_TABLE AS T2 WHERE T.ID=T2.ID AND T2.STATUS='APPROVED'
 )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.5k users

...