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 |
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2008-01-17 : 06:27:28
|
| I have numerous tables in my db and would like to do this: (not sql below just simple explanation'select contacts from wce_contact where idstatus is like 'london%' and select the same contacts where notes are not blank in the table wce_historyHope it makes sense?I just don't know how to query two tables at once... |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-01-17 : 06:31:37
|
| select contactsfrom wce_contactwhere idstatus like 'london%' and contacts in (select distinct contacts from wce_history where notes <> '')==========================================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. |
 |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2008-01-17 : 06:47:19
|
| select contactsfrom wce_contactwhere idstatus like 'london%'I get the first bit ok, the second bit gets abit confusing.and contacts in (select distinct contacts from wce_history where notes <> '')by contacts, do you mean specific records or is this a sql term? As i dont really want to specify 11000 contacts manually you see. If you could just give me an example of how it should look exactly, ill manipulate it into something i need.Thanks! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-17 : 07:10:30
|
quote: Originally posted by Topaz select contactsfrom wce_contactwhere idstatus like 'london%'I get the first bit ok, the second bit gets abit confusing.and contacts in (select distinct contacts from wce_history where notes <> '')by contacts, do you mean specific records or is this a sql term? As i dont really want to specify 11000 contacts manually you see. If you could just give me an example of how it should look exactly, ill manipulate it into something i need.Thanks!
contacts means the field contacts from your table. the subquery returns distinct list of contacts staisfying condition notes <> '' from table and in clause ensures you filter out main query to contain only these contacts' info |
 |
|
|
|
|
|