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.
| Author |
Topic |
|
mchilders
Starting Member
5 Posts |
Posted - 2006-04-13 : 10:10:23
|
How do you accomplish something like:select * from invoiceaccountswhere invoicedate, carrier, account in (select invoicedate, carrier, account from invoice) I'm refering specifically to the use of the "in" keyword in looking for a combination of columns. I need this because I'm using a composite key containing those four columns in the invoice table.Thanks |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-04-13 : 10:30:28
|
select * from invoiceaccounts iaInner join invoice i on ia.invoicedate = i.invoicedate and ia.carrier = i.carrier and ia.account = i.account Srinika |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-04-13 : 11:03:19
|
| That may give you multiple hits on the InvoiceAccounts table (assumign multiple Invoice records per InvoiceAccount record), if so you will need a DISTINCT on the results, or a nested sub-select that uses a DISTINCT on the INVOICE tableYou want to get shot of the SELECT * and use named columns, but in the absence of that it would be:SELECT DISTINCT ia.* FROM ...Kristen |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-04-13 : 11:04:34
|
Or this (which might perform slightly better):select * from invoiceaccounts iawhere exists (select * from invoice i where ia.invoicedate = i.invoicedate and ia.carrier = i.carrier and ia.account = i.account) Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-04-13 : 11:21:58
|
| Kristen, I admit my mistake RyanRandall,I learned thatThanks both of you.Because of people like you this site is a source of knowledge.Srinika |
 |
|
|
mchilders
Starting Member
5 Posts |
Posted - 2006-04-13 : 12:00:24
|
| I see. Thanks a lot!I've just not seen "exists" used in a query before. |
 |
|
|
|
|
|