Skip to content
Advertisement

PHP/SQL Find duplicate rows in a column, with the condition that another column is different

I need an SQL query to do the following task:

I have two columns. Column ‘foo’ and column ‘bar’.

The query needs to return results if and only if column ‘foo’ has different values but ‘bar’ has the same values.

For example:

If I was to run the query on the above dataset, then both rows indicated withe arrows above would be returned, because ‘bar’ is the same on both rows, but ‘foo’ is different.

Any help would be appreciated.

Thank you.

Advertisement

Answer

You can do what you want using exists:

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