This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,899 Users
  • 2,269,649 Discussions
  • 7,916,821 Comments

Discussions

Do not include in the LoV the car numbers already used in the second table

AndriiPrincip
AndriiPrincip Member Posts: 36 Red Ribbon
edited Sep 8, 2019 1:34AM in APEX Discussions

I have two tables, in one table “Car number”, I have a list of car numbers there. In the second table “Registered numbers” I have registered car numbers there. In the “Registered Numbers” table, I fill out the form using the LOV list taken from the “Number Table” table. Is it possible to make sure that in the form when filling out "Registered numbers" in the LOV list there are only those numbers that have not been registered before. Since now all the numbers from the “Car number” table appear in the list. Thanks for the help)

<span class="diff-add" style="font-style: inherit; font-weight: inherit; font-family: inherit; background: #d1e1ad; color: #405a04;"><span class="kwd" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #101094;">CREATE</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="kwd" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #101094;">TABLE</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> number_car<br/>id NUMBER</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">(</span><span class="lit" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;">10</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">)</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">,</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/>number varcahar2</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">(</span><span class="lit" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;">10</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">),</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/>date_add varcahar2</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">(</span><span class="lit" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;">30</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">)</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/></span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">);</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/><br/></span><span class="kwd" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #101094;">CREATE</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="kwd" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #101094;">TABLE</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> registered_numbers<br/>id NUMBER</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">(</span><span class="lit" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;">10</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">)</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">,</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/>reg_number varcahar2</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">(</span><span class="lit" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;">10</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">),</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/>date_reg varcahar2</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">(</span><span class="lit" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;">30</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">)</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/></span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">);</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/><br/></span><span class="kwd" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #101094;">select</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="kwd" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #101094;">for</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> form </span><span class="kwd" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #101094;">table</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">  registered_numbers </span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">(</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">LoV</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">);</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/></span><span class="kwd" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #101094;">select</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> number </span><span class="kwd" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #101094;">as</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> num</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">,</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">number </span><span class="kwd" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #101094;">from</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> number_car</span></span>

Tagged:

Answers

  • Pavel_p
    Pavel_p Member Posts: 2,314 Gold Trophy
    edited Sep 7, 2019 10:05AM

    Hi,

    number is a reserved word, so either you have to enclose the column name with double-quotes or (more preferably) give it some other name like CAR_NUMBER (and assuming that your columns are varchar2, not <span class="diff-add" style="font-style: inherit; font-weight: inherit; font-family: inherit; background: #d1e1ad; color: #405a04;"><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">varcahar2</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"></span></span>  you can create a LOV like:

    select n.car_number d, n.id from  number_car n where not exists(select 1 from registered_numbers r where n.id = r.id);--orselect car_number d, id r from number_car where id not in(select id from registered_numbers);

    May I ask why you have 2 tables? Is the relation between tables 1:1 or 1:n (i.e. there can be more records for the same id in REGISTERED_NUMBERS table)?

    Regards,

    Pavel

  • Ora_Learner890
    Ora_Learner890 Member Posts: 368
    edited Sep 8, 2019 1:34AM

    in addition to @Pavel solution, one another way using MINUS as below with appropriate WHERE clause to not mess-up multiple entries found in Second_Table as @Pavel already mentioned for.

    select car_number from table_a  MINUS  select car_number from second_table

    hope you already have done as per Pavel guide you