dbTalk Databases Forums  

How can I select an element that doesn't exists in a table?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss How can I select an element that doesn't exists in a table? in the comp.databases.oracle.misc forum.



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

Default How can I select an element that doesn't exists in a table? - 11-13-2006 , 04:05 AM







Idem.

Thanks in advance,
Jose Luis.


Reply With Quote
  #2  
Old   
Charles Hooper
 
Posts: n/a

Default Re: How can I select an element that doesn't exists in a table? - 11-13-2006 , 05:57 AM






jose_luis_fdez_diaz wrote:
Quote:
Idem.

Thanks in advance,
Jose Luis.
I am not 100% sure what you are trying to accomplish.

Your can select from dual:
SELECT
SYSDATE CURRENT_DATE
FROM
DUAL;

SELECT
'Hello World'
FROM
DUAL;

You can select from a table, bringing along with it a text constant,
and a date constant:
SELECT
SID,
SERIAL#,
'User' TEXT_MESSAGE,
SYSDATE CURRENT_DATE
FROM
V$SESSION;

If you are wanting to return a row, even when a matching value does not
appear in the table, perform an outer join (left outer join) between a
table containing the full list of values and the table of interest:
SELECT
SID,
SERIAL#,
'User' TEXT_MESSAGE,
SYSDATE CURRENT_DATE
FROM
V$SESSION S,
MY_SESSION_HISTORY SH
WHERE
SH.SID=S.SID(+);

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.



Reply With Quote
  #3  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How can I select an element that doesn't exists in a table? - 11-13-2006 , 05:58 AM



jose_luis_fdez_diaz <gfiuni2 (AT) gmail (DOT) com> wrote:
Quote:
Idem.
'Idem' is Latin for 'the same'.

What do you want to tell us?
Or, more to the point, what is your question?

If it is the question in the subject, please clarify what you want.

Are you looking for 'SELECT 42 FROM dual' ?

Yours,
Laurenz Albe


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

Default Re: How can I select an element that doesn't exists in a table? - 11-13-2006 , 08:27 AM




In the table below:

table1
---------
1
2
4
5


select 3 from table1 where not exists (select * from table1 where
row1!=3)

returns:

3
3
3
3

I only want "one" 3.

How can I get it?

PD: Sorry for my little explanation in the last post.


Regards,
Jose Luis.

Laurenz Albe wrote:
Quote:
jose_luis_fdez_diaz <gfiuni2 (AT) gmail (DOT) com> wrote:
Idem.

'Idem' is Latin for 'the same'.

What do you want to tell us?
Or, more to the point, what is your question?

If it is the question in the subject, please clarify what you want.

Are you looking for 'SELECT 42 FROM dual' ?

Yours,
Laurenz Albe


Reply With Quote
  #5  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: How can I select an element that doesn't exists in a table? - 11-13-2006 , 08:42 AM



jose_luis_fdez_diaz schrieb:
Quote:
In the table below:

table1
---------
1
2
4
5


select 3 from table1 where not exists (select * from table1 where
row1!=3)

returns:

3
3
3
3

I only want "one" 3.

How can I get it?

PD: Sorry for my little explanation in the last post.


Regards,
Jose Luis.

Laurenz Albe wrote:
jose_luis_fdez_diaz <gfiuni2 (AT) gmail (DOT) com> wrote:
Idem.
'Idem' is Latin for 'the same'.

What do you want to tell us?
Or, more to the point, what is your question?

If it is the question in the subject, please clarify what you want.

Are you looking for 'SELECT 42 FROM dual' ?

Yours,
Laurenz Albe

Your query would return no rows (not 4 rows with '3').
Still it is unclear, what you try to achieve.
Do you have a sequential values in your table and like find the "gaps"
in this sequence ? If yes, are the start and end values defined ( i.e. ,
if the gap occur at the highest end of your sequence, do you consider
this to be a gap or not) ?

Best regards

Maxim


Reply With Quote
  #6  
Old   
Charles Hooper
 
Posts: n/a

Default Re: How can I select an element that doesn't exists in a table? - 11-13-2006 , 08:57 AM



jose_luis_fdez_diaz wrote:
Quote:
Laurenz Albe wrote:
jose_luis_fdez_diaz <gfiuni2 (AT) gmail (DOT) com> wrote:
Idem.

'Idem' is Latin for 'the same'.

What do you want to tell us?
Or, more to the point, what is your question?

If it is the question in the subject, please clarify what you want.

Are you looking for 'SELECT 42 FROM dual' ?

Yours,
Laurenz Albe
In the table below:

table1
---------
1
2
4
5


select 3 from table1 where not exists (select * from table1 where
row1!=3)

returns:

3
3
3
3

I only want "one" 3.

How can I get it?

PD: Sorry for my little explanation in the last post.


Regards,
Jose Luis.

I suggest a different approach:
Setting up the test case:
CREATE TABLE TABLE1 (ROW1 NUMBER(22));
INSERT INTO TABLE1 VALUES (1);
INSERT INTO TABLE1 VALUES (2);
INSERT INTO TABLE1 VALUES (4);
INSERT INTO TABLE1 VALUES (5);

SELECT
COUNT(*) MATCH_ROWS
FROM
TABLE1
WHERE
ROW1=3;

MATCH_ROWS
==========
0

The above will give you a count of the rows where ROW1 is 3. A count
of 0 implies that 3 is not included in the ROW1 column.

The above does not return the result that you are looking for, which
appears to be 3, if 3 does not appear in column ROW1. To obtain that
result, the above query is modified:
SELECT
DECODE(COUNT(*),0,3,0) NOT_IN
FROM
TABLE1
WHERE
ROW1=3;

NOT_IN
==========
3

If the COUNT is equal to 0, the value 3 is returned, otherwise the
value 0 is returned.

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.



Reply With Quote
  #7  
Old   
jose_luis_fdez_diaz
 
Posts: n/a

Default Re: How can I select an element that doesn't exists in a table? - 11-13-2006 , 09:55 AM




This is what I was looking for.

Thanks for your help.

Regards,
Jose Luis.

Charles Hooper wrote:
Quote:
jose_luis_fdez_diaz wrote:
Laurenz Albe wrote:
jose_luis_fdez_diaz <gfiuni2 (AT) gmail (DOT) com> wrote:
Idem.

'Idem' is Latin for 'the same'.

What do you want to tell us?
Or, more to the point, what is your question?

If it is the question in the subject, please clarify what you want.

Are you looking for 'SELECT 42 FROM dual' ?

Yours,
Laurenz Albe
In the table below:

table1
---------
1
2
4
5


select 3 from table1 where not exists (select * from table1 where
row1!=3)

returns:

3
3
3
3

I only want "one" 3.

How can I get it?

PD: Sorry for my little explanation in the last post.


Regards,
Jose Luis.


I suggest a different approach:
Setting up the test case:
CREATE TABLE TABLE1 (ROW1 NUMBER(22));
INSERT INTO TABLE1 VALUES (1);
INSERT INTO TABLE1 VALUES (2);
INSERT INTO TABLE1 VALUES (4);
INSERT INTO TABLE1 VALUES (5);

SELECT
COUNT(*) MATCH_ROWS
FROM
TABLE1
WHERE
ROW1=3;

MATCH_ROWS
==========
0

The above will give you a count of the rows where ROW1 is 3. A count
of 0 implies that 3 is not included in the ROW1 column.

The above does not return the result that you are looking for, which
appears to be 3, if 3 does not appear in column ROW1. To obtain that
result, the above query is modified:
SELECT
DECODE(COUNT(*),0,3,0) NOT_IN
FROM
TABLE1
WHERE
ROW1=3;

NOT_IN
==========
3

If the COUNT is equal to 0, the value 3 is returned, otherwise the
value 0 is returned.

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.


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.