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!

Locating duplicates ... sort of

Status
Not open for further replies.

Pipe2Path

Programmer
Aug 28, 2001
60
I have a table called Machine 2 of whose columns are called MachineSerial and MachineModel. I've got values like V4 and V4-2B in the MachineModel column. I would like to know all records that have either a V4 or V4-2B in the MachineModel column that have the same serial number in the MachineSerial column.

Any ideas on the SQL query on this?

I tried the following:

select MachineSerial, MachineModel
from Machine
where (MachineModel = 'V4' or MachineModel = 'V4-2B')
group by MachineSerial, MachineModel
having count(MachineSerial) > 1

This doesn't give the desired result.

Thanks in advance
 
Could Be a round about way, but should work

SELECT MachineCode, MachineSerial
FROM Machine M
INNER JOIN
(
SELECT MachineSerial
FROM
(
SELECT MachineSerial
FROM Machine
WHERE MachineModel LIKE 'V4'
)V4
INNER JOIN
(
SELECT MachineSerial
FROM Machine
WHERE MachineModel LIKE 'V4-2B'
)[V4-2B]
ON V4.MachineSerial = [V4-2B].MachineSerial
)MS
ON M.SerialNumber = MS.SerialNumber
WHERE M.MachineModel LIKE 'V4' or M.MachineModel LIKE 'V4-2B'
 
select MachineSerial
from Machine
where (MachineModel = 'V4' or MachineModel = 'V4-2B')
group by MachineSerial
having count(*) > 1


rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top