question

rahulpatil avatar image
rahulpatil asked

write query for get value from same table

suppose this is table name user with content follwing

id name m_id

1 A Null

2 B 1

3 C 1

4 D 2

write select query for output should be

id name m_id

1 A Null

2 B A

3 C A

4 D B

queryselectmysql
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Jon Crawford avatar image
Jon Crawford answered

self join, SELECT t1.id,t1.name,t2.name FROM myTable t1 JOIN myTable t2 ON t1.id=t2.m_id

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.