self-join

What is SELF JOIN and when would you use it? [duplicate]

一笑奈何 提交于 2019-11-26 00:14:19
Possible Duplicate: sql: self-joins explained What is self join and when would you use it? I don't understand self joins so a layman explanation with an example would be great. You use a self join when a table references data in itself. E.g., an Employee table may have a SupervisorID column that points to the employee that is the boss of the current employee. To query the data and get information for both people in one row, you could self join like this: select e1.EmployeeID, e1.FirstName, e1.LastName, e1.SupervisorID, e2.FirstName as SupervisorFirstName, e2.LastName as SupervisorLastName from

How to get matching data from another SQL table for two different columns: Inner Join and/or Union?

浪子不回头ぞ 提交于 2019-11-25 22:55:14
I've got two tables in MS Access that keep track of class facilitators and the classes they facilitate. The two tables are structured as follows: tbl_facilitators facilID -> a unique autonumber to keep track of individual teachers facilLname -> the Last name of the facilitator facilFname -> the First name of the facilitator tbl_facilitatorClasses classID -> a unique autonumber to keep track of individual classes className -> the name of the class (science, math, etc) primeFacil -> the facilID from the first table of a teacher who is primary facilitator secondFacil -> the facilID from the first

Explanation of self-joins

白昼怎懂夜的黑 提交于 2019-11-25 19:03:28
I don't understand the need for self-joins. Can someone please explain them to me? A simple example would be very helpful. pointlesspolitics You can view self-join as two identical tables. But in normalization, you cannot create two copies of the table so you just simulate having two tables with self-join. Suppose you have two tables: Table emp1 Id Name Boss_id 1 ABC 3 2 DEF 1 3 XYZ 2 Table emp2 Id Name Boss_id 1 ABC 3 2 DEF 1 3 XYZ 2 Now, if you want to get the name of each employee with his or her boss' names: select c1.Name , c2.Name As Boss from emp1 c1 inner join emp2 c2 on c1.Boss_id =