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
 Need to query on two seperate tables

Author  Topic 

vivek328
Starting Member

1 Post

Posted - 2008-11-24 : 10:33:04
I have a database named emedia. in there there are two tables invoices and objectlist. table invoices has two columns date and recid, and table objectlist has two columns recid and objectid.

i need to query data on recid for date '2008' (under the table invoices)
then take all those recids recieved and query objectid (under the table objectlist)

how can i get this done? thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 10:36:51
[code]select i.recid,o.objectid
from objctlist o
join invoices i
on i.recid=o.recid
where date >= '20080101'
and date < '20090101'[/code]
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-11-24 : 10:49:48
Another solution some what similar to above

select i.recid,o.objectid
from objctlist o
join invoices i
on i.recid=o.recid
where year(i.date) = 2008

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 10:53:38
quote:
Originally posted by raky

Another solution some what similar to above

select i.recid,o.objectid
from objctlist o
join invoices i
on i.recid=o.recid
where year(i.date) = 2008




this wont use index if you've one present in date field
Go to Top of Page
   

- Advertisement -