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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Query Help

Author  Topic 

kevinq
Starting Member

3 Posts

Posted - 2003-08-19 : 09:57:44
Hi,

I have two tables, one that holds library information and one that holds a list of website url's for each library item.

The following is a cut down version of both tables:

Library Table
id, title,

Website_Library
id,website_url,library_id

library_id is a foriegn key in the website_library.

What I am trying to do is build a query that returns one row with id,title,website_url1,website_url2

website_url1 & 2 are the first two website_url fields from the website_library table relating to the library record.

Any help would be greatfully appreciated.

nr
SQLTeam MVY

12543 Posts

Posted - 2003-08-19 : 10:03:49
select t.id,t.title ,
website_url1 = (select top 1 t2.website_url from Website_Library t2 where t2.library_id = t.id order by t2.id) ,
website_url2 = (select top 1 a.website_url from (select top 2 t2.id, t2.website_url from Website_Library t2 where t2.library_id = t.id order by t2.id) as a order by a.id desc)
from Library t

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

kevinq
Starting Member

3 Posts

Posted - 2003-08-19 : 10:17:28
Thanks Very Much.
Go to Top of Page
   

- Advertisement -