I have a query

SELECT * FROM msg where sender = receiver

In which sender and receiver are two columns of the msg table.

The query works fine. Now my question is :

Is this a self join? I think this is a simple query which compares values from two columns from same table where as in self join we join the table to itself to get resultant table with columns of same table twice.

for example : SELECT * from msg m Join msg p on m.id = p.id;

can any one clarify?

Thanks is advance.

有帮助吗?

解决方案

   SELECT * FROM msg where sender = receiver  

is not a self join.

Self join is just like any other join, except that two instances of the same table will be joined in the query.

It's quite common when you have a table that references itself. Example: an employee table where every employee can have a manager, and you want to list all employees and the name of their manager.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top