Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 16th, 2007, 07:24 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select statement.. help please

hi all :)

can anyone please help me to get a simple select stmt?

i have 3 tables

table1
compid
name

table2
tb2id
compid
recordid

table3
recordid
name

how can i get all the compid, with recordid?

Thank you

 
Old May 16th, 2007, 07:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Is this what you are looking for?
Code:
SELECT * FROM table1 a, table2 b, table3 c
Where a.compid = b.compid and b.recordid = c.recordid
_________________________
- Vijay G
Strive for Perfection
 
Old May 16th, 2007, 07:43 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply.
Sorry for the confusion, a small change in the table3 fields

table3
recid
name

I dont know how to do inner join.
i tried like this, but it gives error.
It will be greatful, if you can point out where i have gone wrong?
OR is this not the way?
Code:
select top 100 percent dbo.table1.[compid] from dbo.table1 inner join 
dbo.table2 on dbo.[table3]
where dbo.table2.[recordid] = dbo.[table3].[recID]
Thank you

 
Old May 16th, 2007, 09:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ideally the join should be like this.
Code:
select top 100 percent dbo.table1.[compid] from dbo.table1 inner join 
dbo.table2 on dbo.table2.[compid] = dbo.[table1].[compid] inner join
dbo.[table3] on dbo.table2.[recordid] = dbo.[table3].[recID]
And see if you are doing the correct type of join for your expected result.

_________________________
- Vijay G
Strive for Perfection
 
Old May 16th, 2007, 09:13 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you.
I got it worked






Similar Threads
Thread Thread Starter Forum Replies Last Post
select statement ??? RinoDM SQL Server 2000 7 June 19th, 2008 08:40 AM
select Statement gregalb SQL Server 2000 3 January 15th, 2008 12:00 AM
select statement help... RinoDM SQL Server 2000 13 January 10th, 2008 08:34 PM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
Select Statement jmss66 Oracle 1 May 27th, 2004 02:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.