Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 15th, 2004, 05:16 AM
Registered User
 
Join Date: Jun 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default outerJoin on same table

I'm used to Oracle and find all this sql-server "outer join" syntax very confusing and unnecesary, but soit. I want to select all Months, together with only the Countries where customertype = 'Consumer'. Looks to me as a outer join, so I made this up ( made it a full outer join to make it more easy):

SELECT
a.Country, b.Month
FROM Data a FULL OUTER JOIN Data b
on a.GuideNr = b.GuideNr
where a.Customertype = 'Consumer'

It gives me only the Months and Countries where a.Customertype = 'Consumer', so I'm missing all other Months. Is sql-server capable of joins to the same table or am I missing something?
Many thanks!!!

 
Old September 15th, 2004, 02:02 PM
Authorized User
 
Join Date: Jul 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default



try splitting it up into two subselects. it's only returning "Consumer" because thats what it states in the where clause.

select distinct month from data -- gets a list of all the months

outer join to

select * from data where customertype='Consumer'





 
Old September 30th, 2004, 07:29 AM
Authorized User
 
Join Date: Sep 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Lalit_Pratihari
Default

Hi,

Alternatively, you can give an alias to your query and again full outer join to Data table on month.

Thanks,

Lalit
Life Means More...;)





Similar Threads
Thread Thread Starter Forum Replies Last Post
very urgent:cals table to indesign table using xsl franklinclinton XSLT 1 December 16th, 2009 03:48 PM
Populate a List Box with Table Names & Table date hewstone999 Access VBA 1 February 27th, 2008 10:10 AM
Update parent table with the sum of child table gbrown SQL Language 2 November 9th, 2004 07:53 AM
(oracle 8i)Alter Table <table> coalesce partition combo Oracle 3 October 13th, 2004 09:35 AM
size of table (type table is table of number) MikoMax Oracle 1 November 19th, 2003 03:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.