Re: Hi -- Query on Joins -
03-12-2006
, 05:05 AM
Yes you need 1 join statement for each table except 1 you want to add
to the query. So for your example
SELECT e.id, n.name, d.designation, s.salary
FROM emp_id e
JOIN emp_name n ON e.id = n.empId
JOIN emp_designation d ON e.id = d.empId
JOIN emp_salary s ON e.id = s.empId
WHERE s.salary > 1000
ORDER BY n.name
I have shown all tables linked to your table emp_id but you can join
tables in different combinations to suit as in
SELECT e.id, n.name, d.designation, s.salary
FROM emp_id e
JOIN emp_name n ON e.id = n.empId
JOIN emp_designation d ON e.id = d.empId
JOIN emp_salary s ON d.id = s.designationId
WHERE s.salary > 1000
ORDER BY n.name
Note I changd the join condition on the emp_salary table.
This is a basic example. The join statement has a lot of variations
to allow for different logic in joins. You need to get a decent SQL
manual to see the possibilities.
Hope this helps
Duncan |