Click here to Skip to main content
15,936,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everybody,

Could any one of you please tell me how to join too many tables like 5 tables and also please enlighten me when do we actually go for VIEW. Kindly provide me couple of real time scenarios regarding them as I am newbie to SQL Server

Thanks in advance..
Posted

 
Share this answer
 
v3
To answer the 1st part of your question, we join the tables depending upon the relationship that we have established ( as per the normalization process). The intention of the join should be able to identity unique using the key values( which can be composite key also).Keep in mind for join use all the keys that have been defined as PK, eliminating a single key could bring in redundant data. For the syntax side alwys use ANSI SQL-99 format :-

SQL
FROM <mytable>
JOIN <newtable> ON ..


The earlier syantx (ANSI-SQL 92) used to be

SQL
FROM <mytable>, <newtable>
WHERE <filter clause="">
The problem with the '92 synatx in SQL Server is that this would create an cross-join which would all together impact the performace of the query.

Now, for views :- As per the definition of view, these are logical structures that have their physical structure stored but not the data,meaning, a view when created contains only the structure the data is fetched from the actual tables when we query a view (unless we have a materialized view in place).

You, can always refer to the BOL for further readings.
 
Share this answer
 
v3
see the below link, which is more helpful for newbies like you..

http://www.w3schools.com/sql/sql_join.asp[^]
http://www.w3schools.com/sql/sql_view.asp[^]
 
Share this answer
 
Hi,

Join should be made according to the criteria.So as per the need and table structure you can retreive the data by using different join.View can be made on joining the different tables and view can be created on repeated usage of data.So if you repeatedly joining the same table and getting the same value,then you can go for View.


Study how to join the tables in tutorial or google it.
 
Share this answer
 
hmm........

lets you have 2 tables named tbl1 and tbl2.

tbl1's column (empid,name,age) and tbl2's column(empid,address)

Now perform the joins

select tbl1.empid,tbl1.name,tbl1.age,tbl2.address
from tbl1 inner join tbl2 on tbl1.empid=tbl2.empid

hope this will help u.
 
Share this answer
 
Hi Vani,

U can put joins more table like below,


SQL
select distinct A.Name,B.usertype,B.loginname,C.designation,C.EmailID,C.mobileNo,D.product,D.amount
         From sa A 
         join user_list B on A.Name=B.name
		left outer Join userinfo C on B.name=C.name
        Join sales D on A.Name=D.name
 
Share this answer
 

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