Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help selecting distinct records 2

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I need to select distinct records in three columns of my table to populate 3 select boxes on my asp page.
I have these records

Country Account Forecast

China A1111 Budget
China A1111 Actual
China A2222 Actual
China A3333 Budget
Japan A2222 Actual
Japan A3333 Actual
Japan A4444 Budget
Japan A5555 Budget
Singapore A3333 Budget
Singapore A6666 Actual


For my first select box - Country, I would only like to have:

China
Japan
Singapore

For my 2nd select box - Account

A1111
A2222
A3333
A4444
A5555
A6666

For my 3rd select box - Forecast

Actual
Budget

Is there a way to select the distint records with only one select statement?
I have this:

"select country, account, forecast from table1 group by country, account, forecast"

and it only "grouped" the country.

Anjy help will be greatly appreciated.

 
MalayGal,

Here is how I might do it with a "single" query:
Code:
select country, account, forecast
  from (select rownum rn, country
          from (select distinct country
                  from malaygal)) a
      ,(select rownum rn, account
          from (select distinct account
                  from malaygal)) b
      ,(select rownum rn, forecast
          from (select distinct forecast
                  from malaygal)) c
 where a.rn(+) = b.rn
   and c.rn(+) = b.rn;

COUNTRY   ACCOUNT FORECAST
--------- ------- --------
China     A1111   Actual
Japan     A2222   Budget
Singapore A3333
          A4444
          A5555
          A6666
Let us know if you like this.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Santa,

A master class in one quick hit.

T

Grinding away at things Oracular
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top