Click here to Skip to main content
11,583,555 members (63,474 online)
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 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  
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?

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

  Print Answers RSS
0 OriginalGriff 430
1 Dave Kreskowiak 230
2 Richard Deeming 220
3 Sergey Alexandrovich Kryukov 220
4 virusstorm 203
0 OriginalGriff 1,523
1 Sergey Alexandrovich Kryukov 995
2 Abhinav S 696
3 Dave Kreskowiak 621
4 Suvendu Shekhar Giri 568


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 5 Dec 2011
Copyright © CodeProject, 1999-2015
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