Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
How to join two tables in sql server 2008?
 
can any one tell me step by step process!!
Posted 4-Dec-11 23:18pm
Comments
S.P. Tiwari at 5-Dec-11 5:23am
   
which type of join you want..?can you be more specific
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

UsersTable       UserRolesTable
 
PK user_id       PK user_role_id
FK user_role_id     role_description   
   username     
   password
 
 
SELECT A.username, B.role_description
FROM UsersTabel A
INNER JOIN UserRolesTable B
ON A.user_role_id = B.user_role_id
 
Thru that very simple example, hope you get it Wink | ;)
 
After that, move to the more advance one. See link below.
Visual Representation of SQL Joins[^]
 
Regards,
Eduard
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

same like
which join you want?
SELECT order_id, product_name, unit_price, supplier_name, total_units
FROM product, order_items
WHERE order_items.product_id = product.product_id;
 
or another Syntax
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
  Permalink  
Comments
Abhiram KA at 5-Dec-11 6:31am
   
k
RatheeshS at 30-Jan-13 7:29am
   
i want one inner join example
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

SELECT productID,productName,categoryName
FROM products
INNER JOIN categories ON products.categoryID = categories.categoryID
 
here Product and categories are tables
go thru this
http://www.sqltutorial.org/sqljoin-innerjoin.aspx[^]
  Permalink  
Comments
Abhiram KA at 5-Dec-11 6:40am
   
is it usefull?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

SELECT FLD1, FLD2 FROM TABLE1 INNER JOIN TABLE2 
ON TABLE1.PRIMARY_KEY=TABLE2.FOREIGN_KEY
 
OR
 
SELECT FLD1, FLD2 FROM TABLE1 , TABLE2 
WHERE TABLE1.PRIMARY_KEY=TABLE2.FOREIGN_KEY
 

Above we are matching the fields of both the tables and extract the record only when the record exists in both the tables.
 
In case of Inner join above both are same and you can use as you like.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 487
1 CPallini 345
2 OriginalGriff 240
3 George Jonsson 159
4 Abdul Samad KP 145
0 OriginalGriff 6,329
1 Sergey Alexandrovich Kryukov 5,700
2 CPallini 4,940
3 George Jonsson 3,469
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 5 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100