dbTalk Databases Forums  

[sql-general] Hi -- Query on Joins

mailing.database.sql-general mailing.database.sql-general


Discuss [sql-general] Hi -- Query on Joins in the mailing.database.sql-general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
v_dinesh1982
 
Posts: n/a

Default [sql-general] Hi -- Query on Joins - 02-24-2006 , 02:23 AM






Hi friends
I have a small query on joins

For Example I have
EMP_ID in TABLE A
EMP_NAME in TABLE B
EMP_DESIGNATION in TABLE C
EMP_SALARY in TABLE D

I would like to retreive data from 4 tables using a JOIN command
Do I need to give more than 1 JOIN in the query?
Please give me the query to do this...

Waiting for your replies

Thanks in Advance

Dinesh






Subscribe: sql-general-subscribe (AT) yahoogroups (DOT) com
Unsubscribe: sql-general-unsubscribe (AT) yahoogroups (DOT) com
List owner: sql-general-owner (AT) yahoogroups (DOT) com
URL: http://groups.yahoo.com/group/sql-general
Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sql-general/

<*> To unsubscribe from this group, send an email to:
sql-general-unsubscribe (AT) yahoogroups (DOT) com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/




Reply With Quote
  #2  
Old   
undercups
 
Posts: n/a

Default 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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.