December 30, 2003 at 1:01 pm
SQL-SERVER (one table)
trck# Pol#
----------------------------------
A-001-111 123-123-01
A-001-111 123-123-01
A-001-111 123-123-03
A-001-111 123-123-04
A-001-111 123-123-05
A-001-112 123-124-05
A-001-112 123-124-05
B-001-111 112-124-05
B-001-111 112-124-05
C-001-001 111-111-11
C-001-001 111-111-11
B-001-003 001-111-11
B-001-003 001-000-11
G-001-001 111-234-001
I need to write SQL which will give all values where Trak# is same but any of the pol# is different. i.e result should be
trck# Pol#
----------------------------------
A-001-111 123-123-01
A-001-111 123-123-01
A-001-111 123-123-03
A-001-111 123-123-04
A-001-111 123-123-05
B-001-003 001-111-11
B-001-003 001-000-11
Thanx
December 30, 2003 at 1:22 pm
I do not completely understand
Please clarify.
Once you understand the BITs, all the pieces come together
December 30, 2003 at 1:31 pm
I need to pull those records from a table X where pol#'s are different for single trck#.
Single trck#(A-001-111) has multiple pol#'s(123-123-01/03/04/05).
pol# and trck# are two columns
trck# = A-001-111
pol# = 123-123-01
December 30, 2003 at 1:44 pm
Is the result set you have in the initial post complete?
I do not get why "B-001-003, 001-111-11" IS in your result set while "B-001-111 112-124-05" is not.
Once you understand the BITs, all the pieces come together
December 30, 2003 at 2:00 pm
because both the pol#'s(112-124-05) are same... I'm looking for those values where pol#'s are different for same trck#.
trck#, pol#
B-001-111, 112-124-05
B-001-111, 112-124-05
December 30, 2003 at 2:21 pm
Something like...
Select trck#, Pol#
From [Table]
Group by trck#, Pol#
Having count(*) = 1
Once you understand the BITs, all the pieces come together
December 30, 2003 at 2:21 pm
SELECT o.Trck#, o.Pol#
FROM Chawra O JOIN
(SELECT Trck#
FROM
(SELECT DISTINCT Trck#, Pol#
FROM Chawra) c
GROUP BY Trck#
HAVING COUNT(*) > 1) x ON x.Trck# = o.Trck#
--Jonathan
--Jonathan
December 30, 2003 at 2:26 pm
SELECT
TrackNmbr
, PolNmbr
From
Table
Group by
TrackNmbr
, PolNmbr
Having Count(*)=1
* Noel
December 30, 2003 at 2:29 pm
WOW!!
That was funny. Three replies almost a once
* Noel
December 30, 2003 at 2:31 pm
Jonathan,
PERFACT.....
Thanx
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply