Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a table with thousand of records and a another table that I am using as a lookup table to join records:Table1IDfield1field2field3Lookup TableAbbrevFullnameI am using something like:Select Field1, field2, fullnamefrom table1 join[lookup table] on table1.field3 = [lookup table].abbrevgroup by fullname, field2, field1This works fine. Now, in the same query, I want to get all of the other records that do not join, and classify them into a group on their on, "other". Is there a quick way of doing this? I would want the other to be available for grouping in the place where fullname is there for all of the other joined records.Thanks
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2006-10-10 : 07:39:25
This should give you a starter
Select ISNULL(t1.fullname, 'Others') AS FullName, t1.Field1, SUM(t2.Field2)from table1 t1LEFT join [lookup table] t2 on t2.abbrev = t1.field3group by t1.fullname, t1.field2
Peter LarssonHelsingborg, Sweden
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts
Posted - 2006-10-10 : 08:51:31
can also have a look at the full outer joinChiraghttp://chirikworld.blogspot.com/