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
 Transact-SQL (2000)
 Query with 3 tables

Author  Topic 

fametown
Starting Member

4 Posts

Posted - 2007-02-26 : 11:35:10
Hi.

Sorry if my english is not very good. :)

I have a problem with a query.

I have 3 tables:

EX
- Id
- IdUsr
- NumExp (is unique)
- ...

USR
- Id
- Name
...

EXUSR
- Id
- NumExp (can be multiple)
- Name


I need extract and order the data of all this tables in one query... but i have a problem because the EXUSR table can have multiple "NumExp" ... and i only one the FIRST NumExp.

Any help?

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-02-26 : 12:58:21
[code]

Select * From EX e
Inner join
USR u on e.[id] = e.[id]
Inner join
(
Select * From ExUsr
Where ID =
(
Select Max(ID) From ExUsr u where u.NumExp = e.NumExp
)
) as ex
on ex.id = e.id
[/code]

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page
   

- Advertisement -