Selecting from two tables and confirming from them despites they not relate

Please I need a query to select from two tables that are not related to each other.
I also want to confirm data's as in verify wether what the user has entered is in accordance with what is in the tables
Examples
the first table is named "Card" and the second table is named "Student_Details"
Card table contains a column named "Pin_Number".
The Student_Details table contains fields such as Exam_Number, Name, Age, Sex.
The user has to Enter the Pin_Number which has to be confirmed in the Card table and Exam_Number which has to be confirmed in the Student_Details table and verify that both data's are correct.
Please I need the SQL and PL/SQL queries for this problem.
Thanks

Hi,
I think you need two different queries
You can write a procedure like:
create or replace procedure p1 (p_pin_number number, p_exam_number)
is
  r_card_row            card%rowtype;
  r_student_details     student_details%rowtype;
  cursor c1 is
  select *
    from card
   where pin_number = p_pin_number;
  cursor c2 is
  select *
    from student_details
   where exam_number = p_exam_number;
begin
  open c1;
    loop
      fetch c1 into  r_card_row;
      exit when c1%notfound;
      ....  do whatever you want..... and the samething you can do with other cursor
    end loop;
  close c1;
end p1;Hope this helps
Ghulam

Similar Messages

  • Select from two tables and insert into a third

    I'm trying to do a select from two tables and do an insert into a third table from the two resulting columns.
    I have the following....
    DECLARE
    tempsid number;
    temphostid number;
    BEGIN
    select "DBSID_ID","ID" into tempsid,temphostid from "DBSIDS","SERVERS"
    where "HOST_SID" like '%'||"DBSID_NAME"||'%'
    and "HOST_NAME" not like 'vio%'
    and exists (select "DBSID_NAME" from DBSIDS)
    order by "DBSID_NAME";
    insert into "DBSID_LOOKUP" ("SIDLOOKUP_ID", "SERVERLOOKUP_ID")
    values(tempsid, temphostsid);
    END;
    run;
    I get the error ....
    ORA-06550: line 11, column 18:
    PL/SQL: ORA-00984: column not allowed here
    ORA-06550: line 10, column 1:
    PL/SQL: SQL Statement ignored
    1. DECLARE
    2. tempsid number;
    3. temphostid number;

    okay ... I tried a different way ...
    DECLARE
    a number;
    b number;
    BEGIN
    select "DBSID_ID","ID" into a,b from "DBSIDS","SERVERS"
    where "HOST_SID" like '%'||"DBSID_NAME"||'%'
    and "HOST_NAME" not like 'vio%'
    and exists (select "DBSID_NAME" from DBSIDS)
    order by "DBSID_NAME";
    insert into "DBSID_LOOKUP" (SIDLOOKUP_ID, SERVERLOOKUP_ID) values (a, b);
    END;
    and now it whines about ...
    ORA-01422: exact fetch returns more than requested number of rows

  • ALV OOps report- getting data from two tables and adding issue

    Hi,
    This is sales employee performance report.
    I need to select all the fields from two tables based on user input ie VKorg, sales employee .
    There is one field callled " Net sales"in both the tables.
    Based on sales employee number, i need to add that net sales which i get from two tables.
    I need to generate single report.
    Can you give some inputs reg. the select query.
    My idea is select all the data from both tables using join statement.
    Thanks

    Hi,
    I have written like this:
    select * from S002 as a join S006 as b
        into table ME->SS002_RAW[]
        where vkorg in me->select_parameters->SO_VKORG[] = vkorg in me->select_parameters->SO_VKORG[]
              and ZZSLSEMP01 in me->select_parameters->SO_so_empl[] = ZZSLSEMP02 in me->select_parameters->SO_so_empl[].
    when i do like that,
    I am getting error
    Incorrect structure of FROM clause . . . .     
    If you give some idea on this
    Edited by: Raja on Apr 22, 2009 11:19 AM

  • Capture from Two Tables and Apply in one Table

    Hi All,
    Is it possible to capture from two tables (master and child table) and apply in one table?
    For example,
    1. DEPT and EMP tables in source database with relation
    DEPT table structure is like DEPT_ID, DEPT_NAME, LOC_NAME
    EMP table structure is like EMP_ID, EMP_NAME, EMP_DOJ, EMP_SAL, DEPT_ID
    2. EMP_DEPT_STAGING in destination database
    EMP_DEPT_STAGING table structure is like EMP_ID, EMP_NAME, EMP_DOJ, EMP_SAL, DEPT_ID. DEPT_NAME, LOC_NAME
    if there is any update in DEPT table, EMP_DEPT_STAGING should get populated with Department and its employee details. Similarly, if there is any update in EMP table EMP_DEPT_STAGING table should get populated with Employee details and along with department detail.
    Is it possible to accomplish this? If yes, could you please provide me some examples?
    Thanks & Regards
    Thiyagu
    Edited by: mt**** on Sep 4, 2011 11:22 PM

    like this
    INSERT @PlantNew  (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID) 
    SELECT p.PlantID,
    p.PlantName,
    CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
    PlantAssistantDirID,
    PlantDirID
    FROM @Plant p
    LEFT JOIN (SELECT PlantID,
    MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
    MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
    @PlantDirector
    GROUP BY PlantID)pd
    ON pd.PlantID = p.PlantID
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
    You're missing a FROM
    insert into @PlantNew
    SELECT p.PlantID,
    p.PlantName,
    CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
    PlantAssistantDirID,
    PlantDirID
    FROM @Plant p
    LEFT JOIN (SELECT PlantID,
    MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
    MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
    from @PlantDirector
    GROUP BY PlantID)pd
    ON pd.PlantID = p.PlantID

  • Fetch data from two tables and insert into one table

    I have similar to the following data in two tables (@Plant, @PlantDirector) and need to consolidate into one table (@PlantNew) as follows.
    DECLARE @Plant TABLE (PlantID INT, PlantName VARCHAR(100))
    INSERT INTO @Plant (PlantID, PlantName) VALUES (1, 'Name One'),(2, 'Name Two'),(3, 'Name Three'),(4, 'Name Four'),(5, 'Name Five'),(6, 'Name Six')
    Director data for the Plants exist in the following table. Assistant value 1 means Assistant Director and 0 means Director. 
    Data exists only for subset of plants and a Plant may have one or both roles.
    DECLARE @PlantDirector TABLE (PlantID INT, PlantDirectorID INT, Assistant bit)
    INSERT INTO @PlantDirector (PlantID, PlantDirectorID, Assistant) VALUES (2, 111, 1),(2, 222, 0),(4, 333, 0),(6,444,1)
    The above data needs to be inserted into one table (@PlantNew) as follows: 
    PlantID in @Plant table is IDENTITY value and needs to be inserted as-is into this table.
    PlantDirExists will get a value of 1 if at least one record exists in @PlantDirector table for a PlantID. PlantAssistantDirID and PlantDirID should be set to the corresponding PlantDirID or NULL appropriately depending on the data.
    DECLARE @PlantNew TABLE (PlantID INT, PlantName VARCHAR(100), PlantDirExists bit, PlantAssistantDirID INT, PlantDirID INT)
    INSERT INTO @PlantNew (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID)
    VALUES (1, 'Name One', 0, NULL, NULL),(2, 'Name Two', 1, 111, 222),(3, 'Name Three', 0, NULL, NULL),(4, 'Name Four', 1, NULL, 333),(5, 'Name Five', 0, NULL, NULL),(6, 'Name Six',1, 444, NULL)
    How do I achieve the above using SQL ? Thanks.

    like this
    INSERT @PlantNew  (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID) 
    SELECT p.PlantID,
    p.PlantName,
    CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
    PlantAssistantDirID,
    PlantDirID
    FROM @Plant p
    LEFT JOIN (SELECT PlantID,
    MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
    MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
    @PlantDirector
    GROUP BY PlantID)pd
    ON pd.PlantID = p.PlantID
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
    You're missing a FROM
    insert into @PlantNew
    SELECT p.PlantID,
    p.PlantName,
    CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
    PlantAssistantDirID,
    PlantDirID
    FROM @Plant p
    LEFT JOIN (SELECT PlantID,
    MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
    MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
    from @PlantDirector
    GROUP BY PlantID)pd
    ON pd.PlantID = p.PlantID

  • Comparing sum from two tables and correct by difference of sum in second t,

    Hello Guys,
    I have a very tricky task that I cant get my head around.
    The sample data looks like that:
    Master Table
    Claim------Booking--------Debit--------Credit------------MasterAmout          
    1------------1----------------D---------------------------------15.3          
    1------------2----------------D---------------------------------480.6          
    1------------3------------------------------C-------------------496.8          
    ------------------------------------------- 0.9          
    Slave Table
    Claim-----Booking-----Debit------------Credit----------SlaveAmout------- SlaveCorrection
    1------------1------------D------------------------------------15.3---------------14.5
    1------------2------------D------------------------------------480.6-------------480.6
    1------------3-----------------------------C-------------------496---------------496
    -------------------------------------------0.1--------------------------------------0.9
    The booking have a total amout of 0.1 but has to be corrected to 0.9 because the master table has 0.9.
    Booking 1 requires a correction so the slave table also has a total of 0.9 (business rule is, corrections only on first booking). so we have
    to change the amount from 15.3 to 14.5. I plan my SQL like that:
    1. Sum bookings from both tables for each Claim. Compare the two for each individual claim.
    2. If the Master sum of the amount shows a difference between the master and slave table
         2.1 select top 1 booking from slave table for the specific claim and increase/decrease by the difference of those two amounts.
    Does that make sense?

    Hello
    It would be really helpful if you could a) format your posting properly using the {noformat}{noformat} tags around your data and b) provide create table/ insert statements.
    Anyway, from what you described -
    Booking 1 requires a correction so the slave table also has a total of 0.9 (business rule is, corrections only on first booking). so we haveto change the amount from 15.3 to 14.5
    You could achieve this with an analytic function and an outer join...WITH Master_Table AS
    SELECT 1 Claim, 1 booking, 'D' debit,NULL credit,15.3 masteramount from dual union all
    SELECT 1,2,'D',NUll,480.6 from dual union all
    SELECT 1,3,NULL,'C',496.8 from dual
    Slave_Table AS
    ( SELECT 1 claim, 1 booking, 'D' debit, null credit, 15.3 slaveamount,14.5 slavecorrection from dual union all
    SELECT 1,2,'D',NULL,480.6,480.6 from dual union all
    SELECT 1,3,null,'C',496,496 from dual
    SELECT
    m.claim,
    m.booking,
    m.debit,
    m.credit,
    NVL(s.slavecorrection,m.masteramount) amount
    FROM
    master_table m
    LEFT OUTER JOIN
    ( SELECT
    claim,
    booking,
    slaveamount,
    slavecorrection,
    ROW_NUMBER() OVER(PARTITION BY claim ORDER BY booking) rn
    FROM
    slave_table s
    ) s
    ON
    ( s.claim = m.claim
    AND
    m.booking = s.booking
    AND
    s.rn = 1
    CLAIM BOOKING D C AMOUNT
    1 1 D 14.5
    1 2 D 480.6
    1 3 C 496.8
    HTH
    David                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Retrieve data from two tables and store it in one itab

    Hi All,
    i have an internal table of structure which has fields ar_object and objecttext.
    I want to retrieve all the ar_object from table toaom for object type BUS2012 and then the corresponding objecttext from toasp where toaom-ar_object = toasp-ar_object and then store both this values in my internal table.
    what is the best method to do it ?  Please let me know if you want to know how i am doing it right now
    thanks,
    Golu

    Hi,
    You can get many ways 
    1. using  For all entries in 
    2. using Inner join
    3. you can get 2 tables data into 2 different internal tables  and   loop first internal table and read second internal using key fields append it another internal table or modify second internaltable.
    In above ways 1st and 2nd are performance issues.   the best way is
    get TOAOM table data into itab1 and get TOASP table data into itab2 you can append data into another itab3 or modify itab2
    regards,
    Ganesh

  • Get user count from two tables and display in 1 row

    I have 2 tables.....
    Table1 Table2
    user date user date
    With 1 query, I want to display the user, the count of the number of times a user appears in Table1.user as count1 and the count of the number of times that same user appears in Table2.user as count2 between a specific time period. I have looked and tried things including joins, unions, nested loops but can't get anything to work. The result would appear like this:
    USER COUNT1 COUNT2
    john 100 2
    doe 1000 200
    Thank you for your time. I'm really stuck and confused.

    Hi,
    Welcome to the forum!
    I think the easiest way to do this is to do a GROUP BY query on each table separately, and then combine the results, using FULL OUTER JOIN or UNION.
    WITH     union_data     AS
         SELECT       user_name
         ,       COUNT (*)     AS count1
         ,       0              AS count2
         FROM       table1
         WHERE       dt     >= &start_dt
         AND       dt      <  &end_dt + 1
         GROUP BY  user_name                             -- Forgot this originally!
    UNION ALL
         SELECT       user_name
         ,       0              AS count1
         ,       COUNT (*)     AS count2
         FROM       table2
         WHERE       dt     >= &start_dt
         AND       dt      <  &end_dt + 1     
         GROUP BY  user_name                             -- Forgot this originally!
    SELECT       user_name
    ,       SUM (count1)     AS count1
    ,       SUM (count2)     AS count2
    FROM       union_data
    GROUP BY  user_name
    ;Edited by: Frank Kulash on Jul 29, 2009 1:34 PM
    Edited by: Frank Kulash on Jul 29, 2009 2:46 PM
    As Solomon pointed out, I forgot the GROUP BY clauses in the sub-query.
    Without the tables, I can't test it.

  • Selecting from two tables but making it just one selection

    Is there a way to select from two tables and just have one selection appear?
    Specifically I have a fact_install_unit, and a fact_install_arch table.
    Sometimes the value exists in fact_install_unit.factory_timestamp, and sometimes when fact_install_unit.factory_timestamp is null I need to pull it from the fact_install_arch.factory_timestamp.
    sort of like:
    (select fact_install_unit.factory_timestamp
    from fact_install_unit, fact_install_arch
    where fact_install_unit.fl_unit_sak = fact_install_arch.fl_unit_sak
    and where fact_install_unit.factory_timestamp is null then display fact_install_arch.factory_timestamp)

    > I was just stating that I do not have sufficient priveleges to create views in this database.
    >
    nm means "no more" than that
    And how are we supposed to know that? You seem to have changed the thread subject to "unfortunately I only have read-only and insufficient priveleges", which is not even a question.
    nm means "New Mexico":
    http://www.myshortpencil.com/schooltalk/messages/85/515.html?971794944

  • Fetch the data from two tables

    hell all
    i want to fetch the data from two tables, one is from internal table and another one is data base table. what syntax i have to use either FOR ALL ENTRIES or INNER JOIN?

    hi
    Use FOR ALL ENTRIES.
    see the sample code
      select * into table tvbrk from vbrk
                                where fkart in ('F2', 'F3', 'RE',
                                           'ZVEC' , 'ZVEM' , 'ZVED',
                                           'S1')
                                and erdat in so_erdat
                                and kunag in s_kunag. 
                                      erdat in so_erdat
                               and   fkart in ('F2', 'F3', 'RE',
                                                 'ZVEC' , 'ZVEM').
    if not tvbrk is initial.
        select * into table t_zregion from zregion
                      for all entries in tvbrk
                       where country = tvbrk-land1
                       and   region = s_regio.
      endif.
    thanks
    sitaram

  • Can we create a BAM data Object from two tables

    Hi ,
    I want to pull the data from two tables and create a BAM data object, Is it possible in BAM?
    Do the needful
    Regards,
    Francis

    The sample way is using AQ on database. You can create a database view to join the tables. And create AQ on the view, create a ems to listen on the queue.

  • To Select the data from two table one is transp table and onther is cluster

    Hi All,
    I want to select the data from two tables
    Here i am giving with an example.
    Fileds: kunnr belnr from bseg.  table bseg
    fields: adrnr from kna1     table: kna1.
    Know i want to put these into one internal table based on kunnr and belnr.
    Thanks in advance.
    Ramesh

    Hi,
       U cant use joins on cluster table and BSEG is a cluster table so use FOR  ALL ENTRIES for taht
    refer this code
    *&      Form  sub_read_bsak
          text
    -->  p1        text
    <--  p2        text
    FORM sub_read_bsak.
    *--Select data from BSAK Table
      SELECT lifnr
             augdt
             augbl
             gjahr
             belnr
             xblnr
             blart
             dmbtr
             mwskz
             mwsts
             sgtxt
             FROM bsak
             INTO CORRESPONDING FIELDS OF TABLE it_bsak
             WHERE belnr IN s_belnr
             AND   augdt IN s_augdt.
      IF sy-subrc EQ 0.
    *--Sort table by accounting document and vendor number
        SORT it_bsak BY belnr lifnr.
      ENDIF.
    ENDFORM.                    " sub_read_bsak
    *&      Form  sub_read_bseg
          text
    -->  p1        text
    <--  p2        text
    FORM sub_read_bseg.
      IF NOT it_bsak[] IS INITIAL.
    *--Select data from BSEG table
        SELECT belnr
               gjahr
               shkzg
               kostl
               hkont
               ebeln
               ebelp
               FROM bseg
               INTO CORRESPONDING FIELDS OF TABLE it_bseg
               FOR ALL ENTRIES IN it_bsak
               WHERE belnr EQ it_bsak-belnr
               AND   gjahr EQ it_bsak-gjahr
               AND   shkzg EQ 'S'.
        IF sy-subrc EQ 0.
    *--Sort table by accounting document
          SORT it_bseg BY belnr.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_read_bseg

  • Need of SQL query in selecting distinct values from two tables

    hi,
    I need a query for selecting distinct values from two tables with one condition.
    for eg:
    there are two tables a & b.
    in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
    here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
    can anybody please help me.
    Thanks in advance,
    Ratheesh

    Not sure what you mean either, but perhaps this will start a dialog:
    SELECT DISTINCT a.empno,
                    a.name,
                    a.sex,
                    b.salary,
                    b.doj
    FROM    a,
            b
    WHERE   a.empno = b.empno;Greg

  • Selecting from one table and Update another in the same Page

    Could someone help me with this HTMLDB task. In my page design, I am selecting data from two tables (masters: DEPT, EMP) which I want to display on the left column of the page and at the same time a user would be able to update another table (ATTENDANCE:with many children) which would have a radiogroup on the right side for each value of the master such as employee name. The placement of data has to appear in corresponding rows on the page. For instance, employee names of the master table must appear on the same row with its corresponding child value. The page would be grouped by DEPT_NO. The user would click on the department name, a new page with the employee name would apprar. From that page, the user would then update attendance column for each employee in that department. In this operation, it is only the ATTENDANCE table that is being updated. I can send out more information about the structure of the tables if you need more information. I tried many HTMLDB options, forms, reports, etc. I have not been able to get quite right. Your help will be appreciated.

    Raju,
    Thanks for responding to my problem. I have actually tried using the example on how-to you sent me a link to but it did not help as I expected. You see, the page would be updated every meeting date for each employee. I can send you more information about the table structure if you like. However, let me see if this will help you a bit.
    Tables are: 1) Dept [dept_no (pk),dept_name] 2) EMP [emp_no (pk),emp_name, dept_no(fk)] 3) Meetings [meet_key(pk),attended, meeting_date, emp_no(fk)]
    What I want to do is create two pages, one would list the departments, when a user selects a department, the user would be linked to a meeting attandance page. The meeting attendance page would list department name once, Meeting date once, and then list employees in that department. At the right column of every employee would be a checkbox for meeting.attended for update. The meeting_date would be pre-populated so that what the user would do is just check Yes/NO. The second page is the one I'm having the most problem with.
    If I can do a fetch from dept, emp, and meetings and then do an update on the Meetings table on the same page, I think that might solve the problem. That was how I solved it in MS Access three years ago.
    Here is email address in case you want to contact me directly. [email protected]
    Thanks again for your help.

  • Select data from two tables...!

    HI Experts...!
    i m a beginner user and i want to select data from two tables proj and prps.....using joins.....and internal tables i have written a code...
    SELECT prps~pspnr
           prps~objnr
           prps~psphi
           proj~ernam
           proj~erdat
           proj~pspnr
    INTO  table itab   -
    itab is internal table
    FROM prps inner join proj
    WHERE pspnr in p_no and prpspsphi = projpspnr.
    but there is error in from clause ..please help me....
    Advance thanx....

    Hi,
    check the sample code bellow above two reply will solve out your problem but one more extra line in your code pointed out bellow.
    TABLES: prps, proj.
    TYPES:  BEGIN OF ty_test,
            pspnr LIKE prps-pspnr,
            objnr LIKE prps-objnr,
            psphi LIKE prps-psphi,
            ernam LIKE proj-ernam,
            erdat LIKE proj-erdat,
            END OF ty_test.
    DATA: itab TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.
    SELECT-OPTIONS: p_no FOR prps-pspnr.
    SELECT  prps~pspnr
            prps~objnr
            prps~psphi
            proj~ernam
            proj~erdat
    *        proj~pspnr " No need for this you have selected this in
    *     the first line because it is commone so you only need to select from any one
            INTO TABLE itab
    FROM prps INNER JOIN proj ON ( prps~pspnr = proj~pspnr  )
    WHERE prps~pspnr IN p_no.
    Best Regards,
    Faisal
    Edited by: Rob Burbank on Dec 24, 2009 12:24 PM

Maybe you are looking for

  • File loss over network on Mac Pro /windows

    Hi I hope someone can help, I have been using my network for over a year with no problems also networked the same for the last 4 years. I now have files and folders go missing when dragging between computers I have one mac pro and x2 windows computer

  • Why can't I delete any of previously found destinations in the apple maps?

    Is there a way to delete destinations in apple maps, like there is in mapquest or gpsdrive?

  • Automatic clearing for bills of exchange

    HI, We are looking at ways to make a automatic clearing with special G/L indicator for bill of exchange. Does anyone who knows the way to make this recording from f.13 or similar tcode? Thanks Best Regards

  • Bulk load messages into the language repository?

    Hi, Our existing, pre-APEX, applications make use of a common table of 'messages' to provide multiple language support e.g. we have a lookup against message number and language to produce the required message. This seems very similar to the functiona

  • How download only selected part of a podcast ?

    Hi, anyone can help me to find a tip to download only a pattern matching selected part of a podcast feed? For example, think about to download only the feed contents where the title contains a specific word . Is it possible in iTunes ? bye