Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
suppose I hv 3 tables
1st table:
ID UserName Address

2nd Table:
productID Items Price

3rd table
ID productID


here 3rd table I want to get the relation of the first and 2nd table with respect to their ID's.. Can ny1 tel me how to query it???
Posted
Updated 27-Dec-11 18:32pm
v2

If you are a beginner and want to get help in your works here is another solution :

Open Sql Server Management Studio and connect to a DB. the click on new query then right click on the newly opened window then select Design query in editor.
By using that wizard you can add any table that you want to the query designer and by dragging one table field to another table field you can apply joins on specific field.
If they have related foreign keys it automatically creates JOIN statements.

Try to study those auto created JOINs to learn how to join two table.
And also have a look at these resources :
http://beyondrelational.com/blogs/nakul/archive/2011/07/14/ssms-query-designer-ad-hoc-query-writing-editing-made-simple.aspx[^]

http://devguru.com/technologies/t-sql/7114.asp[^]

http://www.sql-tutorial.net/SQL-JOIN.asp[^]

Hope it helps.
 
Share this answer
 
Comments
Nihal Hussain 28-Dec-11 1:16am    
nt a beginner.. I have not worked much on multiple joins
Amir Mahfoozi 28-Dec-11 1:29am    
So to support yourself in JOINing tables use query designer but in the meanwhile try to study more about it. Good Luck ;)
SQL
select id,productid,username,address,items,price from 1sttable,2ndtable,3rdtable where id.1sttable=id.3rdtable and productid.2ndtable=productidtable


i think this may help u... and this is non-ascci
 
Share this answer
 
v2
Comments
nagendrathecoder 28-Dec-11 0:51am    
using JOINs is much better option than writting plain queries.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900