Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to join two tables by select command?

Author  Topic 

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-04-11 : 09:54:39
Hi

I have a tables like below

TblA

ID(unique)---SessionID(unique)----Ref

TblB

VisitID(unique)---SessionID(Multiple)----Page--Pdcode


My question : How Do I bring all rows from TblB and matching single row from TblA (I have more than one sessionID in TblB and only one Unique SessionID in TblA).

The Select query I was using is


SELECT     PageViews.ID AS ID, PageDetailView.VisitID, PageViews.PageAccessed, PageDetailView.PageAccessed AS Expr1, PageViews.QueryString, 
PageDetailView.QueryString AS Expr2, PageViews.Referer, PageViews.SessionID, PageDetailView.SessionID AS Expr3, PageDetailView.PdtID,
PageDetailView.Pcode, PageDetailView.CustID, PageDetailView.OrdTot, PageViews.[Date]
FROM PageViews RIGHT OUTER JOIN
PageDetailView ON PageViews.SessionID = PageDetailView.SessionID
ORDER BY PageViews.ID DESC

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-11 : 11:57:43
just join them using the matching SessionID column. Or was your question to display the TblA information only once without repeating for each TblB row?
Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-04-14 : 04:39:34

Hi Visak


My question was display the TblA information only once without repeating for each TblB row.


quote:
Originally posted by visakh16

just join them using the matching SessionID column. Or was your question to display the TblA information only once without repeating for each TblB row?

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-14 : 04:43:39
So how do you want to show the matching values from TblB? or are you interested in showing only one value from TblB (latest,earliest,random) ?
Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-04-14 : 05:01:23
Hi I want All rows from TblB and single matching (matching by sessionID)row from TblA but not repeated rows from TblA. Sorting by TblB.ID Desc.

TblA has Unique SessionID and there is no duplicates
TblB Has Many SessionID

I am tring to create views first, then use asp.net to call views to display the tailored information about web stats, sales etc.


quote:
Originally posted by visakh16

So how do you want to show the matching values from TblB? or are you interested in showing only one value from TblB (latest,earliest,random) ?

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-14 : 05:09:57
This is a presentation issue.
If you have one record in tblA and two records in tblB with same SessionID, you get row "rows" back from tblA because you match that row two times.

Just turn on "Suppress/hide duplicate values" in your report designer.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-04-14 : 06:10:36
Hi

Thanks for the reply. I will try to log all session ID to one table. Need Some advice on the following.

1. I am going to create many "Views" from One table.
2. AM I ABLE TO USE "Procedures" for the "Views" ?

quote:
Originally posted by Peso

This is a presentation issue.
If you have one record in tblA and two records in tblB with same SessionID, you get row "rows" back from tblA because you match that row two times.

Just turn on "Suppress/hide duplicate values" in your report designer.



E 12°55'05.25"
N 56°04'39.16"


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-14 : 06:29:41
You can use procedures on your views. You use views in same manner as tables as views are nothing but virtual tables. Also you can create more than 1 view from a table.
Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-04-14 : 06:58:57
Hi

Thanks a lot guys.

quote:
Originally posted by visakh16

You can use procedures on your views. You use views in same manner as tables as views are nothing but virtual tables. Also you can create more than 1 view from a table.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-14 : 07:09:39
quote:
Originally posted by Vaishu

Hi

Thanks a lot guys.

quote:
Originally posted by visakh16

You can use procedures on your views. You use views in same manner as tables as views are nothing but virtual tables. Also you can create more than 1 view from a table.





You are welcome
Go to Top of Page
   

- Advertisement -