Friday, March 23, 2012

query two tables to get data

Does anyone know how to query two tables to get data? I need something
like this
select * from registrations where regstatus='R' and select * from
classtop where ClassID equals the value of the first select statement.
So for exmaple:
The first select Statement will give me from registration:
id, ClassID, RegStatus, Date, UserID
I need the second select statement to give me from classtop:
(id=ClassID from first query)
id, ModuleID, Date, location
Thanks in advance for your help
Lisa
peashoe@.yahoo.com wrote:
> Does anyone know how to query two tables to get data? I need something
> like this
> select * from registrations where regstatus='R' and select * from
> classtop where ClassID equals the value of the first select statement.
> So for exmaple:
> The first select Statement will give me from registration:
> id, ClassID, RegStatus, Date, UserID
> I need the second select statement to give me from classtop:
> (id=ClassID from first query)
> id, ModuleID, Date, location
> Thanks in advance for your help
> Lisa
>
SELECT
Reg.ID,
Reg.ClassID,
Reg.RegStatus,
Reg.Date,
Reg.UserID,
Class.ID,
Class.ModuleID,
Class.Date,
Class.Location
FROM dbo.Registration AS Reg
INNER JOIN dbo.ClassTop AS Class
ON Reg.ClassID = Class.ID
Tracy McKibben
MCDBA
http://www.realsqlguy.com
|||use inner join
select * form registrations reg inner join classtop cla on cla.ClassID
=reg.ClassID
will get u data fro both table that matches ClassID
vinu
"peashoe@.yahoo.com" wrote:

> Does anyone know how to query two tables to get data? I need something
> like this
> select * from registrations where regstatus='R' and select * from
> classtop where ClassID equals the value of the first select statement.
> So for exmaple:
> The first select Statement will give me from registration:
> id, ClassID, RegStatus, Date, UserID
> I need the second select statement to give me from classtop:
> (id=ClassID from first query)
> id, ModuleID, Date, location
> Thanks in advance for your help
> Lisa
>

No comments:

Post a Comment