dbTalk Databases Forums  

SELECT in problem

comp.databases.oracle.server comp.databases.oracle.server


Discuss SELECT in problem in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Pedro
 
Posts: n/a

Default SELECT in problem - 03-03-2010 , 08:45 AM






Good morning people. I need quiet an odd help in here. Let me see if I
can explain it.

I have an SELECT WHERE IN (<list of ids>).
Let us say that I sent the following list of ids: 1, 2 and 3.

There is only resulting records for the ID = 3, but I'd like to see
all the ids, even if they don't have records...
I expect the following result for instance:

ID DESC
1
2
3 Test

Any suggestion on how to do this? I have here the complete statement,
but I don't think it would help for now...

Reply With Quote
  #2  
Old   
Carlos
 
Posts: n/a

Default Re: SELECT in problem - 03-03-2010 , 09:13 AM






On Mar 3, 2:45*pm, Pedro <pedro.p... (AT) gmail (DOT) com> wrote:
Quote:
Good morning people. I need quiet an odd help in here. Let me see if I
can explain it.

I have an SELECT WHERE IN (<list of ids>).
Let us say that I sent the following list of ids: 1, 2 and 3.

There is only resulting records for the ID = 3, but I'd like to see
all the ids, even if they don't have records...
I expect the following result for instance:

ID * * DESC
1
2
3 * * *Test

Any suggestion on how to do this? I have here the complete statement,
but I don't think it would help for now...
OUTER JOIN with a table 'ad-hoc' for the desired values (possibly with
a 'WITH' sentence)

HTH.

Cheers.

Carlos.

Reply With Quote
  #3  
Old   
jefftyzzer
 
Posts: n/a

Default Re: SELECT in problem - 03-03-2010 , 03:25 PM



On Mar 3, 5:45*am, Pedro <pedro.p... (AT) gmail (DOT) com> wrote:
Quote:
Good morning people. I need quiet an odd help in here. Let me see if I
can explain it.

I have an SELECT WHERE IN (<list of ids>).
Let us say that I sent the following list of ids: 1, 2 and 3.

There is only resulting records for the ID = 3, but I'd like to see
all the ids, even if they don't have records...
I expect the following result for instance:

ID * * DESC
1
2
3 * * *Test

Any suggestion on how to do this? I have here the complete statement,
but I don't think it would help for now...
An elaboration of Carlos's sugestion:

WITH
IDS AS
(
SELECT
1 ID
FROM
DUAL
UNION ALL
SELECT
2
FROM
DUAL
UNION ALL
SELECT
3
FROM
DUAL
),
T AS
(
SELECT
3 ID, 'TEST' DESCR
FROM
DUAL
)
SELECT
I.ID,
T.DESCR
FROM
IDS I
LEFT JOIN
T
ON
I.ID = T.ID
ORDER BY
1;

--Jeff

Reply With Quote
  #4  
Old   
Marconelli
 
Posts: n/a

Default Re: SELECT in problem - 03-04-2010 , 08:55 AM



Uzytkownik "jefftyzzer" <jefftyzzer (AT) sbcglobal (DOT) net> napisal w wiadomosci
news:07c710d1-5277-4e8f-971f-4d5dfb7764aa (AT) q21g2000yqm (DOT) googlegroups.com...
On Mar 3, 5:45 am, Pedro <pedro.p... (AT) gmail (DOT) com> wrote:
Quote:
Good morning people. I need quiet an odd help in here. Let me see if I
can explain it.

I have an SELECT WHERE IN (<list of ids>).
Let us say that I sent the following list of ids: 1, 2 and 3.

There is only resulting records for the ID = 3, but I'd like to see
all the ids, even if they don't have records...
I expect the following result for instance:

ID DESC
1
2
3 Test

Any suggestion on how to do this? I have here the complete statement,
but I don't think it would help for now...
Here's a little nicer version:

WITH counter AS (SELECT level id FROM dual CONNECT BY level <=3)
SELECT c.id, t.*
FROM counter c
LEFT OUTER JOIN table t ON c.id = t.id

Reply With Quote
  #5  
Old   
jefftyzzer
 
Posts: n/a

Default Re: SELECT in problem - 03-04-2010 , 01:50 PM



On Mar 4, 5:55*am, "Marconelli" <m... (AT) NOSPAM (DOT) go2.pl> wrote:
Quote:
Uzytkownik "jefftyzzer" <jefftyz... (AT) sbcglobal (DOT) net> napisal w wiadomoscinews:07c710d1-5277-4e8f-971f-4d5dfb7764aa (AT) q21g2000yqm (DOT) googlegroups.com...
On Mar 3, 5:45 am, Pedro <pedro.p... (AT) gmail (DOT) com> wrote:



Good morning people. I need quiet an odd help in here. Let me see if I
can explain it.

I have an SELECT WHERE IN (<list of ids>).
Let us say that I sent the following list of ids: 1, 2 and 3.

There is only resulting records for the ID = 3, but I'd like to see
all the ids, even if they don't have records...
I expect the following result for instance:

ID DESC
1
2
3 Test

Any suggestion on how to do this? I have here the complete statement,
but I don't think it would help for now...

Here's a little nicer version:

WITH counter AS (SELECT level id FROM dual CONNECT BY level <=3)
SELECT c.id, t.*
* FROM counter c
* LEFT OUTER JOIN table t ON c.id = t.id
"SELECT level id FROM dual CONNECT BY level <=3"--very nice ;-)

--Jeff

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.