Click here to Skip to main content
14,603,917 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 2

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 :-

FROM <mytable>
JOIN <newtable> ON ..


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

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.
   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 3

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[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 6

Hi Vani,

U can put joins more table like below,


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
   

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




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