Skip to content
Advertisement

SELECT if 2 cells in a row are equal

Tried to show it as simple as possible. I want to SELECT Subject if 2 cells in a row are equal

Table

---------------------------------------------
Subject  ---  username  --- Lastpostername 
---------------------------------------------
subject A --- user1    ---  user3
Subject B --- user2    ---  user3
Subject C --- user3    ---  user3
Subject D --- user4    ---  user1

Result I need is to select subject C cause username and lastpostername are equal (Sorted DESC by ID, so newest comes first)

Advertisement

Answer

SELECT t.subject
FROM tab AS t
WHERE t.username = t.Lastpostername
ORDER BY t.id DESC
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement