If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Challenging query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-24-11, 03:56
wungexh wungexh is offline
Registered User
 
Join Date: Nov 2011
Posts: 19
Challenging query

Dear Query Gurus,

Hope you are doing great.Its a simple query to retrieve data with the Order_ID.If the record is there its fine and can retrieve the data.

But my query is to retrieve the list of order_id which has no records in database.

Plz help me to write a query.


Thanks
Reply With Quote
  #2 (permalink)  
Old 11-24-11, 04:04
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
Quote:
Originally Posted by wungexh View Post
But my query is to retrieve the list of order_id which has no records in database.
How do you expect to retrieve something from the database that is not there.

I guess you are not telling the important parts.

Please post:
  • your table definitions (as CREATE TABLE, not as screenshots) and please use [code] tags to make your code readable.
    See here for details: http://www.dbforums.com/misc.php?do=bbcode#code
  • sample data in those tables
  • the expected output of your query based on the sample dat.
Reply With Quote
  #3 (permalink)  
Old 11-25-11, 00:24
jonathan3880 jonathan3880 is offline
Registered User
 
Join Date: Nov 2011
Location: USA
Posts: 1
re

Hey ...This is very nice post that you have posted here. I am impressed. Keep it up.
Reply With Quote
  #4 (permalink)  
Old 11-25-11, 03:22
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Maybe it is about missing IDs, and the solution is one of row generator techniques. For example, let's create a table and insert some records in there:
Code:
SQL> create table test (id number);

Table created.

SQL> insert all
  2    into test values (1)
  3    into test values (4)
  4    into test values (5)
  5    into test values (8)
  6    into test values (10)
  7  select * from dual;

5 rows created.

SQL>
It is obvious that IDs that are missing are 2, 3, 6, 7 and 9. OK then, let's find them!

First, using a CONNECT BY clause, create the whole ID set:
Code:
SQL> select level id
  2    from dual
  3    connect by level <= (select max(id) from test);

        ID
----------
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10

10 rows selected.
One more step to a solution - using a MINUS set operator, find missing IDs:
Code:
SQL> select level missing_id
  2    from dual
  3    connect by level <= (select max(id) from test)
  4  minus
  5  select id
  6    from test;

MISSING_ID
----------
         2
         3
         6
         7
         9
That would be all, I guess.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On