FYP FYP - 1 month ago 15
SQL Question

selecting the same data in different row from database

enter image description here

i need to select the 'name' attributes must same value with 'seek' attribute.
is kind like a match making concept which i need to select the 'name' attribute = 'seek' attribute in same table
so the outcome will be

name | seek
HEADPHONE | KETTLE
KETTLE | HEADPHONE


anyone can give me the solution on how to do it. i currently doing my final year project. Thank you

Answer
SELECT t1.NAME,
       t1.SEEK
FROM yourTable t1
INNER JOIN yourTable t2
    ON t1.NAME = t2.SEEK AND
       t1.SEEK = t2.NAME

If you want to report only one record for each SEEK/NAME pair, then you can try:

SELECT DISTINCT LEAST(t1.NAME, t1.SEEK),
                GREATEST(t1.NAME, t1.SEEK)
FROM yourTable t1
INNER JOIN yourTable t2
    ON t1.NAME = t2.SEEK AND
       t1.SEEK = t2.NAME