Forum

Posted by Sana, Sept. 6, 2023, 7:17 a.m.

SQL

How to find the same values for columns in single SQL table

Answers

Can you expand on what you're trying to do a little more as there are various ways this might work.

You can check for rows where multiple columns have the same value (ie, WHERE col1 = col2).

You can also do a self-join, such as:

SELECT a.employee_id, a.name, b.name as supervisor_name

FROM employees a 

LEFT JOIN employees b

ON a.supervisor_id = b.employee_id

 

The details depend on exactly what you're wanting to do with a given dataset.

Great example Mike! Thanks for sharing your thoughts on this.

Leon, Oct. 1, 2023, 6:56 p.m.
SQLPad user avatar

Mike (228)

Sept. 9, 2023, 2:51 p.m.

Hi Sana,

Are you talking about finding duplicates in a column?

If so, you can group by that column and count them, and use HAVING COUNT(*) > 1 to find them.

Hope it helps,

-Leon

SQLPad user avatar

Leon (949)

Oct. 1, 2023, 6:55 p.m.