query lines, where...

I have a table with 3 columns.
Most of the data are not unique in these 3 columns, the data are same like this:
1, 2, 3
1, 2, 3
1, 2, 3
4, 5, 6
4, 5, 6
4, 5, 6
4, 5, 6
6, 7, 7
6, 7, 8
7, 7, 8
7, 6, 7
As you can see the lines broke no uniqueness:
 
6, 7, 7--this is ok
6, 7, 8--this is not ok because we expected 6, 7, 7 at last column again
7, 7, 8--not ok, because there exist "x, 7, X" combinations more with different x-es.
7, 6, 7--not ok, we expected 7,7,8
You can ask about these lines not ok?

I want to make sure these 3 columns always have in data from the table as
1, 2, 3
1, 2, 3
1, 2, 3
4, 5, 6
4, 5, 6
4, 5, 6
4, 5, 6
6, 7, 7
6, 7, 7
7, 60, 70

Something like that, maybe:

with my_table as (select 1 col1, 2 col2, 3 col3 from dual union all
                  select 1 col1, 2 col2, 3 col3 from dual union all
                  select 1 col1, 2 col2, 3 col3 from dual union all
                  select 4 col1, 5 col2, 6 col3 from dual union all
                  select 4 col1, 5 col2, 6 col3 from dual union all
                  select 4 col1, 5 col2, 6 col3 from dual union all
                  select 4 col1, 5 col2, 6 col3 from dual union all
                  select 6 col1, 7 col2, 7 col3 from dual union all
                  select 6 col1, 7 col2, 8 col3 from dual union all
                  select 7 col1, 7 col2, 8 col3 from dual union all
                  select 7 col1, 6 col2, 7 col3 from dual),
      results as (select col1,
                         col2,
                         col3,
                         count(distinct col2) over (partition by col1) col2_count,
                         count(distinct col3) over (partition by col1) col3_count
                  from   my_table)
select col1,
       col2,
       col3
from   results
where  col2_count > 1
or     col3_count > 1;

      COL1       COL2       COL3
---------- ---------- ----------
         6          7          7
         6          7          8
         7          6          7
         7          7          8

Tags: Database

Similar Questions

  • This line where you can see your bookmarks and stuff are gone... ! How can I get that back?

    my laptop is 93.1% full so its quite slow work... I was on a website and I tried to click right (I needed to copy something) and the computer was slow, it didn't work. (already happened). so I tried a few times right click and before I new it this line where you can see your bookmarks (and other stuff) had disappeared. ! I tried right click again to see if I could get back, but it did not work. then I tried to turn off the computer and it still does not work. How can I get that back? and if I get it back, all my favorites will be gone?

    Versions of Firefox 3.6 + have a feature to allow the user to hide the Menu bar.

    Press the Alt key to temporarily show the Menu bar, then open view > toolbars and select menu bar, so it has a check mark.

    The F10 can also be used on most PCs to temporarily reveal the menu bar.

    https://support.Mozilla.com/en-us/KB/menu+bar+is+missing

  • Repeat the query lines

    I have two tables pecourses and teachcourses with the following desc

    pecourses

    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    CSTDT NOT NULL DATE
    COURSCOD NOT NULL VARCHAR2 (5)
    COURSDOCNO NOT NULL VARCHAR2 (15)
    COURSDOCDT NOT NULL DATE
    TRSTYPE NOT NULL VARCHAR2 (1)
    DATE OF CENDDT
    QUALIFYING VARCHAR2 (2)
    PARTNO VARCHAR2 (3)
    VARCHAR2 (6) MAJOR
    HOURNO NUMBER (3)

    teachcourses

    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    EMPNO NOT NULL VARCHAR2 (5)
    CSTDT NOT NULL DATE
    COURSCOD NOT NULL VARCHAR2 (5)
    COURSDOCNO NOT NULL VARCHAR2 (15)
    COURSDOCDT NOT NULL DATE
    CHAR (1) PARTICIPANT
    HOURSNO NUMBER (3)
    TEACHER NOT NULL NUMBER (3)

    I will execute a query as follows:

    SQL > select p1.courscod, p1.cstdt, p1.cenddt and p2.cenddt in the p1, p2 pecourses pecourses where
    P1.courscod = P2.courscod and p1.cstdt = p2.cstdt and p1.cenddt <>p2.cenddt and
    P1.courscod in (select courscod from the teachcourses where empno = '3056')

    the object of the application is to retrieve the rows that have the same code of classes and the start of the course, but differ by the
    date this employee 3056 has taught for the courses.

    the issue: the query works very well but there are recurrences as follows:

    the line

    P1.courscod = 016900
    P1.cstdt = 30-6-2008
    P1.cenddt = 4-7-2008
    P2.cenddt = 5-7-2008

    would be repeated in the output as follows

    P1.courscod = 016900
    P1.cstdt = 30-6-2008
    P1.cenddt = 5-7-2008
    P2.cenddt = 4-7-2008

    is there a way to eliminate this repetition?

    Thank you in advance.

    Perhaps you could add a condition of p1.cenddt< p2.cenddt="">
    don't know if that's exactly what you want, but it will eliminate the duplicate output example you provided

  • to find values common to different lines, whereas a column is different

    Hi all!
    It was difficult to write about it, but the problem will clear with this example:

    I have the following table with two columns, one for the user id and the second for id book. I'm writing a sql query to search for users who have read the same books.
    u_id  b_id
    -----   ------
    1      122
    1      185
    1      231
    1      316
    1      329
    1      355
    2      110
    2      151
    2      260
    2      376
    2      539
    .      .
    .      .
    .      .
    1077      1
    1077      19
    1077      34
    1077      39
    1077      47
    1077      50
    First thing came to mind was the following:
    SELECT * FROM myTable a WHERE b_id = (SELECT b_id FROM myTable b WHERE b.u_id <> a.u_id)
    But, Yes, it gives the error subquery returns more than one line. Is is possible to do?

    reis3k wrote:

    I'm writing a sql query to search for users who have read the same books.

    Do you mean find two (or more) users who read the same book? If so:

    with t as (
               select 1 u_id,122 b_id from dual union all
               select 1,185 from dual union all
               select 1,231 from dual union all
               select 1,316 from dual union all
               select 1,329 from dual union all
               select 1,355 from dual union all
               select 2,110 from dual union all
               select 2,151 from dual union all
               select 2,260 from dual union all
               select 2,376 from dual union all
               select 2,539 from dual union all
               select 3,110 from dual union all
               select 3,151 from dual union all
               select 3,260 from dual union all
               select 3,376 from dual union all
               select 3,539 from dual union all
               select 1077,1 from dual union all
               select 1077,19 from dual union all
               select 1077,34 from dual union all
               select 1077,39 from dual union all
               select 1077,47 from dual union all
               select 1077,376 from dual
              )
    select  b_id,
            rtrim(xmlagg(xmlelement(e,u_id,',').extract('//text()') order by u_id),',') user_list
      from  t
      group by b_id
      having count(*) > 1
    /
    
          B_ID USER_LIST
    ---------- ----------
           110 2,3
           151 2,3
           260 2,3
           376 2,3,1077
           539 2,3
    
    SQL>  
    

    Or do you mean find two (or more) users who read exactly the same set of books? If so:

    with t as (
               select 1 u_id,122 b_id from dual union all
               select 1,185 from dual union all
               select 1,231 from dual union all
               select 1,316 from dual union all
               select 1,329 from dual union all
               select 1,355 from dual union all
               select 2,110 from dual union all
               select 2,151 from dual union all
               select 2,260 from dual union all
               select 2,376 from dual union all
               select 2,539 from dual union all
               select 3,110 from dual union all
               select 3,151 from dual union all
               select 3,260 from dual union all
               select 3,376 from dual union all
               select 3,539 from dual union all
               select 1077,1 from dual union all
               select 1077,19 from dual union all
               select 1077,34 from dual union all
               select 1077,39 from dual union all
               select 1077,47 from dual union all
               select 1077,376 from dual
              )
    select  book_list,
            rtrim(xmlagg(xmlelement(e,u_id,',').extract('//text()') order by u_id),',') user_list
      from  (
             select  u_id,
                     rtrim(xmlagg(xmlelement(e,b_id,',').extract('//text()') order by b_id),',') book_list
               from  t
               group by u_id
            )
      group by book_list
      having count(*) > 1
    /
    
    BOOK_LIST                      USER_LIST
    ------------------------------ -----------
    110,151,260,376,539            2,3
    
    SQL> 
    

    SY.

  • Query execution where Clause

    Hi I have the where cluase as below, I would like to know how does oracle decides that one to run first.

    WHERE S.PERSPECTIVE = S"
    and s.shipment_gid = sb.shipment_gid
    AND SB. BILL_GID = CBIL. INVOICE_GID
    and inv.invoice_gid = cbil.invoice_gid
    AND S.SOURCE_LOCATION_GID = LC. LOCATION_GID
    and l.location_gid = lc.location_gid
    AND TRUNC (cbil.insert_date) = TRUNC (tc.tesco_cal_date)
    AND (lc.location_gid = ' n ' GOLD lc.corporation_gid = 'TESCO.10719')
    AND s.source_location_gid = lc.location_gid
    AND tc.tesco_year = '2013'
    AND tc.tesco_period = 6
    AND tc.tesco_week_number = 23

    Hello

    The optimizer will generally fruit first.  If there is a condition that is easy to perform and pass down overall results much, it will make this condition before another which is more difficult to perform, or who does not have so many lines.  For example, if there are clues on tc.tesco_period and tc.tesco_week_number, but not tc.tesco_year, then it will probably run one of the conditions that can be done with an index before it only the condition concerning tc.tesco_year.  Is there are 53 different possible values for tc.tesco_week_number, but only 6 possible values for tc_tesco_period, then it will be provided on tc.tesco_week_number (and exclude the approximately 52/53 lines) before it not thatt condition probably implies tc.tesco_period (which excludes approximately 5/6 lines).

    There are always exceptions.  As others have already said, look at the execution plan if you really want to know.

  • Amplify the query lines

    G ' Day in the SQL forum,.

    I am looking for an elegant solution to this problem, and so far nothing comes to mind (except maybe something scary like the clause type)

    In light of this test scenario:
    create table my_table
      (id   number
      ,name varchar2(100)
      ,qty  number
    );  
    
    insert into my_table values (1, 'Scott', 3);
    insert into my_table values (2, 'Penny', 2);
    insert into my_table values (3, 'Eddie', 1);
    insert into my_table values (4, 'Ray'  , 1);
    I want my output to be
    ID  NAME  
    --- -----
    1   Scott
    1   Scott
    1   Scott
    2   Penny
    2   Penny
    3   Eddie
    4   Ray
    That's why amplify each line by the number in the field.

    Just as I posted one solution I came with implied analytical, but I think it could be better.
    select * from (
      select id, name, qty
       ,row_number() over (partition by name order by null) rn
      from my_table 
      connect by level <= 2)
    where qty >= rn
    Any ideas for something cleaner?

    Scott.
    select t.*
      from my_table t,(select rownum no from dual connect by rownum <= (select max(qty) from my_table)) x
     where no <= qty
     order by id
    
  • Any text strings have new lines where they shouldn't

    Using AS3 in flash CS4

    Hi I have a text imported from a bounded/separated tab (.txt) text file.

    I divided the values in a table using .split ('\n').split('\t')

    I stored the data imported into a table where each column has a new index and the properties of each line can be obtained from the table [n] .property. For example, array [4] .name would give the "entity name 4th in the original text file."

    This all works fine however some of the separate strings are formatted incorrectly that they absorb 2 lines instead of one.

    The first string in each line of the original text file is imported into flash with a new line above him. "That is to say: 'Property1' in the text file delimited: original separation/tab is stored in flash as"

    Property1"with a new line above it. I need to get rid of this new line in order to correctly display the text in the text fields.

    Can someone please.

    PS: I will not change my file format import from a file delimited text tab, something like xml, so please don't suggest that he.

    those who are not functions of string-band.  These are white space characters.  all white space characters are ignored by the backslash character.

    I used two of them and in my years of using the flash, I've never used more than these two and \t = tab, even if I know two other:

    \b = RET.

    \f = page break

    I used:

    \r = carriage return

    \n = new line

    the code I gave converted a break line, followed by a newline on a new line, only.  and he converted a carriage return followed of a new line on a new line, only.

    Please mark this thread as answered, if you can.

  • Query the WHERE statement to compare the date of reference db

    Hello

    I can't get this where statement of work. I have now so is not to throw errors, but it does not what it is supposed to.
    I'm looking to match my table of documents date with the current calendar date, if there is a match, my cfif will take this match and make a link in the appropriate date. (it's a small calendar with the month and day of the week with dates, each date will be normal, agree, that if there is a record for this date, it establishes a link.

    This is my code, as I said, it does not have an error, but it doesn't work either.

    My query:

    < name cfquery = "CaleventRec" datasource = "#APPLICATION.dataSource #" >
    SELECT events.eventDate, events.ID AS ID
    Events
    WHERE eventDate > = #CreateODBCDate("07/12/2005") # AND eventDate = #Days #.
    < / cfquery >

    It's the cfif statement:

    < cfoutput query = "CaleventRec" >
    < cfif days EQ ' #eventdate # ' >
    < a href = "detail.cfm? id = #ID # ' > #Days # < /a >
    < / cfif >
    < / cfoutput >

    This is all the code together:

    < name cfquery = "CaleventRec" datasource = "#APPLICATION.dataSource #" >
    SELECT events.eventDate, events.ID AS ID
    Events
    WHERE eventDate > = #CreateODBCDate("07/12/2005") # AND eventDate = #Days #.
    < / cfquery >
    <!-the variable ThisDay value 0. This value remains 0 until the day of the week on which falls the first day of the month is reached. ->
    < cfset ThisDay = 0 >
    <!-loop through until the number of days of the month is reached. ->
    < cfloop condition = "ThisDay LTE days" >
    < b >

    <!-loop well that every day of the week. ->
    < cfloop from = "1" = "7" index = "LoopDay" >
    <!-this turns every day into a hyperlink if it is a current or future->
    < cfoutput query = "CaleventRec" >
    < cfif days EQ ' #eventdate # ' >
    < a href = "detail.cfm? id = #ID # ' > #Days # < /a >
    < / cfif >
    < / cfoutput >

    <!--

    If ThisDay is always 0, check to see if the day of the week in the loop corresponds to the day of the week for the first day of the month.
    If the values match, the ThisDay 1 value.
    Otherwise, the value remains 0 until the day of the week.
    ->
    < cfif ThisDay IS 0 >
    < cfif DayOfWeek (ThisMonthYear) IS LoopDay >
    < cfset ThisDay = 1 >
    < / cfif >
    < / cfif >
    <!--
    If the ThisDay value is always 0 or exceeds the number of days in the month, display nothing in the column. Otherwise, displays
    the day of the month and the increment value.
    ->
    < cfif (ThisDay IS NOT 0) AND (ThisDay LTE days) >
    < cfoutput >
    <!-I chose to highlight the day of the year using an IF-ELSE. ->
    < cfif (#ThisDay # EQ #currentday #) AND (#month # EQ #startmonth #) AND (#year # EQ #startyear #) >
    < td align = "center" bgcolor = "# FFFF99" >
    < cfset #dateformat = dayview (createdate (#year #, #month #, #thisday #), ' mm/dd/yyyy') # >
    < class are 'calendartoday' = > #ThisDay # < / make >
    < table >
    < cfelse >
    < td align = "center" >
    < cfset #dateformat = dayview (createdate (#year #, #month #, #thisday #), ' mm/dd/yyyy') # >
    < class font = "calendar" > #ThisDay # < / make >
    < table >
    < / cfif >
    < / cfoutput >
    < cfset ThisDay = ThisDay + 1 >
    < cfelse >
    < td > < table >
    < / cfif >

    < / cfloop >
    < /tr >
    < / cfloop >

    I know my where is incorrect, I'm not too sure if my cfif statement is correct either. Can someone help me understand this?

    Thank you!

    CFmonger

    Start by dumping the result of the query and see if you get what you expect to get.  If this isn't the case, look at the value of your variable to days.

    Furthermore, cela

    AND eventDate = #Days #.

    Converts this

    redundant.

  • How to find the lines, where the second column only has a defined value

    I have a table like
    CREATE TABLE MY_MAP
    (
      USERID     NUMBER(10)                    NOT NULL,
      SYSTEMID  NUMBER(10)                    NOT NULL,
    )
    The data in the table can be as below
    INSERT INTO MY_MAP VALUES(1,6);
    INSERT INTO MY_MAP VALUES(2,6);
    INSERT INTO MY_MAP VALUES(3,6);
    INSERT INTO MY_MAP VALUES(1,9);
    INSERT INTO MY_MAP VALUES(2,7);
    Now my requirement is to find all these IDS that are at systemid 6 but not at 9. That is to say

    2.3. [since 1 is both in the 6 and 9], should not be recovered.

    I did two courses is a loop. Can someone give me a single query to do?
    SQL> select * from MY_MAP m
      2  where SYSTEMID=6
      3  and 0=(select count(*) from MY_MAP m2 where m2.USERID=m.USERID and m2.SYSTEMID=9);
    
        USERID   SYSTEMID
    ---------- ----------
             3          6
             2          6
    

    or

    SQL> select * from MY_MAP m
      2  where SYSTEMID=6
      3  and NOT EXISTS (select 1 from MY_MAP m2 where m2.USERID=m.USERID and m2.SYSTEMID=9);
    
        USERID   SYSTEMID
    ---------- ----------
             3          6
             2          6
    

    or

    SQL> select * from MY_MAP m
      2  where SYSTEMID=6
      3  and userid not in (select userid from MY_MAP m2 where m2.SYSTEMID=9);
    
        USERID   SYSTEMID
    ---------- ----------
             3          6
             2          6
    

    or

    SQL> select userid
      2  from MY_MAP
      3  where SYSTEMID in (6,9)
      4  group by userid
      5  having sum(decode(SYSTEMID,9,1,0))=0;
    
        USERID
    ----------
             2
             3
    

    Max
    http://oracleitalia.WordPress.com

    Published by: Massimo Ruocchio March 1, 2010 10:43

  • Sub query in where clause

    I have the following code which continues to throw an error:
    select distinct game_code, count(player_id) 
    from customer_data.cd_nhl_gm_tender_stats t
    where  
    (select distinct player_id
     from customer_data.cd_nhl_gm_tender_stats
     where season_id = 200818)
    group by game_code, player_id
    having count(player_id) > 1
    Error indicates that there is an expression just before the group, by thoughts?

    The subquery is mainly used to find a value unique player_id (so there no line duplicates in the result set.)

    Examples of data;
    customer_data.cd_nhl_gm_tender_stats t
    Game_code player_id
    88484           545454
    88484           545454
    88484           545454
    There are of course other columns in the table above, but ultimatly it is multiple lines for each game.
    I'm just trying to back each game_code where do I find the more then a player_id.

    Hello

    user652714 wrote:
    It kinda turns out to be the right id, but to provide clarification. I want to find each game_code where more then two DIFFERENT player_id lie... hope it explains what better things

    This looks like

    
    GROUP BY  game_code
    HAVING    COUNT (DISTINCT palyer_id) > 2
    

    If you need help, post some sample data and the results desired from these data.

  • Query IN WHERE

    Hi, I have two tables

    (1) users with the user name fields, email, name...
    and importedContacts with the fields email, name, of contactIDFK

    Say for example users has the following lines

    (1) 1. [email protected] | A
    (2) 2. [email protected] | B
    (3) 3. [email protected] | C

    And the imported Contacts has the following lines
    (1) [email protected] | S | NULL VALUE
    (2) [email protected] | J | NULL VALUE
    (3) [email protected] | A | NULL VALUE
    (4) [email protected] | B | NULL VALUE

    I want my request for updates to the contactIDFK table to importedContacts (line 3) field 1
    (line 4) and 2

    For now I have UPDATE importedContacts SET contactIDFK =? WHERE by email at (email SELECT FROM importedContacts);

    Any help is appreciated.

    Published by: user650521 on October 16, 2008 17:34
    update importedcontacts i
    set    i.contactidfk = (select u.userid
                            from   users u
                            where  u.email = i.email
                            and    u.name  = i.name
                           )
    where  exists          (select u.userid
                            from   users u
                            where  u.email = i.email
                            and    u.name  = i.name
                           )
    ;
    
  • The film shared iMovie displays noise and horizontal lines where I have added a few pictures

    I've added a few photos at the end of my film (about 7 min long, 4 k, but to 1020), but at the beginning a few black and white lines appear instead of the photo and this also happens with another photo.

    Are you by chance using iMovie 11 (version 9)?  This does not work with still photos under El Capitan, only the last version, 10.1.2.

    Geoff.

  • When I write an e-mail, my address of signature is now a straight line, where it is used in the parameter "preformat". How to restore the normal signature?

    I want to restore my "signature" below my reply or a message to look like this:

    John Bliss
    any where
    all over town

    Anytime anywhere
    

    Instead, it looks like this:

    John Bliss anywhere, anywhere around town

    It used to be (until 3 days ago) as the former. I can't find how to get back to this style. Also, the top of the message when you enter an email address to the person that you are sending is now blue instead of white as it was.

    Please notify.

    Thank you

    John Bliss

    Hi John, is this a problem in Firefox on a site in Thunderbird or webmail?

    If it's on a webmail site, you could mention who it is?

    Is it possible that you change your composition between HTML and plain text format?

  • Insert a default line where there is no data

    Hi using Oracle 10 g, I stuck a simple simulation below... I would like to insert a default value of "42" to the province of "AB", is a set of records for all products that do not exist in all provinces, would therefore create a line with the corresponding province to the right join.  Hope this makes sense...


    CREATE TABLE TBL_TEST1

    (PROD_ID VARCHAR2 (10), VARCHAR2 (2) OF THE PROVINCE, THE NUMBER OF PRIZES);

    INSERT ALL

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', "BC", 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'MT', 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'NB', 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', "NF", 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'NS', 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'ON', 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'PI', 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'SK', 178)

    SELECT * FROM DUAL;

    -SELECT * FROM TBL_TEST1

    CREATE TABLE TBL_PROV

    (PROV. VARCHAR2 (2));

    INSERT ALL

    IN TBL_PROV (PROV) VALUES ("AB")

    IN TBL_PROV (PROV) VALUES ("BC")

    IN TBL_PROV (PROV) VALUES ("MT")

    IN TBL_PROV (PROV) VALUES ('NB')

    IN TBL_PROV (PROV) VALUES ('NC')

    IN TBL_PROV (PROV) VALUES ('NS')

    IN TBL_PROV (PROV) VALUES ('ON')

    IN TBL_PROV (PROV) VALUES ("PI")

    IN TBL_PROV (PROV) VALUES ('SK')

    SELECT * FROM DUAL;

    -SELECT * FROM TBL_PROV;

    SELECT

    A.PROD_ID

    COALESCE(A.PROVINCE, B.PROV)

    NVL(A.PRICE,0)

    Of

    TBL_TEST1 HAS

    RIGHT OUTER JOIN

    TBL_PROV B

    WE A.PROVINCE = B.PROV;

    3031421 wrote:

    Hi Frank,.

    So I want the select to return all the lines by product ID.  Not all ID's products are available in all provinces.  So, using the Province TBL_PROV list table as a reference, I want to show a line for each province Product_ID in the TBL_PROV table.  The select statement, I posted does not list the product ID for the "AB" province, so even if there are 8 rows in the product table, yes I would show 9 lines with the overall product id...

    42 BRITISH COLUMBIA 178
    42 MT 178
    42 NB. 178
    42 NF 178
    42 NS 178
    42 WE 178
    42 PI 178
    42 SK 178
    42 AB 0

    Good, then you don't want to INSERT new data into a table. you just want to a new row in the result set.

    It would be helpful if you posted some examples of data for tbl_test1 who had a couple of prod_ids different and different prices.

    You want all prod_id in tbl_test1 combined with all the provinces of the tbl_prov?

    If so, you can use an outer join partitioned, like this:

    SELECT t.prod_id

    p.prov

    , COALESCE (t.price, 0) IN the price

    OF tbl_prov p

    LEFT OUTER JOIN tbl_test1 t PARTITION BY (t.prod_id)

    ON t.province = p.prov

    ORDER BY prod_id

    Prov.

    ;

    Why did you use COALESCE to the provinces, but prices NVL?  If you like COALESCE, as it would be infinitely faster, wouldn't it faster in both places?  If you like NVL because it is easier to code, it will be easier to code in both places?

    In this case, you have no need either for the province, assuming that tbl_prov is never NULL (and even if this is the case, it will never reach the join condition).

    Almost no one is never using RIGHT OUTER JOIN, because the same results are always possible with LEFT OUTER JOIN.  Partitioned outer joins operate in the same way that you use the LEFT or RIGHT.  It's as if you did a separate outer join for each value of the partitioning column, and and made a UNION ALL operation to combine all separate them the results.

  • See the line where counter is ZERO?

    I'm counting the number of entries in each UNI.
    However, I do not get a count to 0

    I would like to return to be:
    UNI     Entries
    POL     1
    GYM     3
    XXX     0
    THE ID TABLE
    CREATE TABLE DAN_GR
    (ID    VARCHAR2(8),
    UNI    VARCHAR2(8)) 
    
    INSERT INTO DAN_GR (ID,UNI) VALUES (1,'POL');
    INSERT INTO DAN_GR (ID,UNI) VALUES (2,'GYM');
    INSERT INTO DAN_GR (ID,UNI) VALUES (3,'GYM');
    INSERT INTO DAN_GR (ID,UNI) VALUES (4,'GYM');
    TABLE OF THE BANK
    CREATE TABLE DAN_BANK2
    (UNI    VARCHAR2(8)) 
    
    INSERT INTO DAN_BANK2 (UNI) VALUES ('POL');
    INSERT INTO DAN_BANK2 (UNI) VALUES ('SYM');
    INSERT INTO DAN_BANK2 (UNI) VALUES ('XXX');
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi

    It looks like a typo in in the sample data; The SYMBOL should have GYM? If so, you get your o/p desired, if not for SYM you will get 0 as count of output.

    select uni,
                (
                  select count(b.id) --count(b.id)
                    from dan_gr b
                   where b.uni = a.uni
                ) cnt
      from dan_bank2 a;
    
    UNI      CNT
    -------- ----------------------
    POL      1
    GYM      3
    XXX      0      
    

Maybe you are looking for