Folks,
All am looking for is to extend the INNER JOIN. Let me just get to the point. I have two tables Dept & Emp. One Dept can have multiple Emp’s & not the other way around.
Table Dept Dept_id Dept_Name 1 IT 2 HR 3 Other Table Emp Emp_id Dept_id Emp_Name 11 1 John 12 1 Jill 13 2 Jack 14 3 Jared 15 1 Jim 16 1 Jarret 17 2 Jacob I need to JOIN it on Dept_id Expected Results Dept_id Dept_name Emp_id Emp_Name 1 IT 11 John NULL NULL 12 Jill NULL NULL 15 Jim NULL NULL 16 Jarret 2 HR 13 Jack NULL NULL 17 Jacob 3 Other 14 Jared
Hope I conveyed what i want precisely. Its just a regular Inner Join on a Foreign Key Constraint. But, I want the values from the First Table (Dept) to be NULL-ed except for the First Match. That being said, I don’t care what’s the first match. See it below – Just the result for the Dept_id 1.
Expected Results (Only for Dept_id = 1) It could be Dept_id Dept_name Emp_id Emp_Name 1 IT 11 John NULL NULL 12 Jill NULL NULL 15 Jim NULL NULL 16 Jarret OR Dept_id Dept_name Emp_id Emp_Name 1 IT 15 Jim NULL NULL 12 Jill NULL NULL 11 John NULL NULL 16 Jarret OR Two other possibilities.
Thanks in advance. Sorry for the long explanation even though its a simple case.
I agree with Ic. that this is a crazy query that seems to be doing something that your application should be doing instead of your sql query, that being said, it’s fun to write those queries 🙂