Skip to content
Advertisement

Select Distinct and show records where X column is not the same

I have a database with a structure of:

enter image description here

I am struggling to write a query to show me where ‘Supp’ is different. (Supp Should be the same for all records, So i need to identify records effected to correct) The table contains more than 55,000 lines

Just a list of Codes where Supp is not the same for each of the Location would be sufficient. Selecting distinct or group by but unsure how to query the Supp if different. For example with the above Data: 1478 and 5689 would be the effected lines.

Any help would be greatly appreciated.

Advertisement

Answer

In the simplest case, to get a list of Codes that have more than one Supp:

Output:

If you want to get the full rows (or partial by changing SELECT *), try something like:

Output:

See this in action on sqlfiddle.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement