0

Table

   id | name       | type          |    x          | y           | z                | refer
 -----+------------+---------------+---------------+-------------+------------------+-----------------
 1001 | A          |          4    |               |             |                  |           0
 2000 | B          |          2    |   -1062731776 |             |           -65536 |        1001
 2001 | C          |          2    |     167772160 |             |        -16777216 |        1001
 2002 | D          |          2    |   -1408237568 |             |         -1048576 |        1001

I need to select columns name,x,y,z if in refer column it refers to id column and name must be of that id's name. Is it possible with a single query? can anyone please help here, output should be:

name| x               |     y       | z
----+-----------------+-------------+-----------------
 A  |   -1062731776   |             |           -65536
 A  |     167772160   |             |        -16777216 
 A  |   -1408237568   |             |         -1048576 
0

1 Answer 1

1
SELECT t1.name, t2.x, t2.y, t2.z FROM TABLENAME t1
JOIN TABLENAME t2 on t1.id = t2.refer
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.