Home How to find all entries with reference to yourself?
Reply: 2

How to find all entries with reference to yourself?

Nips
1#
Nips Published in 2017-09-13 10:40:03Z

I have table with id and parent_id fields and I want to show all entries with reference to yourself, something like this:

select * from mytable where id=parent_id;

How to do this?

Kristofer
2#
Kristofer Reply to 2017-09-13 10:42:37Z

You can do it with an inner join:

SELECT * FROM mytable m1
INNER JOIN mytable m2 ON m2.id = m1.parent_id
Muhammad Yahya
3#
Muhammad Yahya Reply to 2017-09-13 10:45:59Z

You need to apply Self Join select * from mytable a,mytable b where id=parent_id;

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308977 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO