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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-01-18 : 08:37:23
|
| Graeme writes "I am using 2 views:customersAndOrders2005 and customersAndOrders2006The views contain the same fields.I want to display only those details which are in the 2005 viewbut not in 2006 view. I could use:SELECT * FROM a MINUSSELECT * FROM bexcept that I don't want it to use all of the columnsto work this out. I want to use surname and postcode.So,SELECT surname, postcode FROM a MINUSSELECT surname, postcode FROM bThis returns the rows that I want, but I wantall of the field '*' in my result set.How do I do this? I am only using SQL 2000, SP4.(I realise MINUS is not valid in sql 2000)I could use row_number, but sql 2000 does have this either.Thanks!" |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-01-18 : 08:44:17
|
| [code]Select a.*from aleft join b on a.surname = b.surname and a.postcode = b.postcodewhere b.surname is NULL and b.postcode is NULL[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-18 : 09:25:22
|
| Too bad it is not SQL Server 2005.SELECT surname, postcode from aexceptselect surname, postcode from bPeter LarssonHelsingborg, Sweden |
 |
|
|
gbarnett
Starting Member
1 Post |
Posted - 2007-01-19 : 03:26:33
|
| Thanks for your replies.I resolved the problem by creating a new field surcode (surname concateated postcode. I then said something like:select * from 2005where surcode not in ( select surcode from 2006). |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-19 : 03:36:40
|
Why?The suggestion Harsh provided does the same thing and faster.This is fast tooSelect a.*from awhere not exists (select null from b where b.surname = a.surname and b.postcode = a.postcode) Peter LarssonHelsingborg, Sweden |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-01-19 : 03:46:44
|
| Some people doesn't bother to accept the suggestions...they are happy to implement their own...even if it causes them lot more efforts and bad performance. After they get performance hit, they turn again here to ask for tuning their slow performing queries.(Reactive rather than Proactive approach).Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|