Create a view from multiple tables

Hi all,
I am a newbie, so sorry if this is a "basic" question.
I had 3 tables TAB1, TAB2 and TAB3
TAB1 has
STU_ID(pk), NAME, GRADE, ADDRESS
TAB2 has
COURSE_ID(pk), STU_ID(fk), COURSE_NAME, ROOM_NUM, TIME, DAY
TAB3 has
MENTOR_NAME, TITLE, AVAILABLE_DAYS
Now I want to create a view(or query) that returns STU_ID, COURSE_NAME, NAME, GRADE, MENTOR_NAME and TITLE.
When I tried writing a query like
SELECT a.STU_ID, b.COURSE_NAME, a.NAME, a.GRADE, c.MENTOR_NAME, a.TITLE
FROM TAB1 a, TAB2 b, TAB3 c
WHERE a.STU_ID=b.STU_ID
I am getting multiple results..like I'm getting Mentor name 4 times, name 4 times like that.
So can anybody help me in writing the query for this....a "VIEW" would be appreciated.
Thanks In Advance
Srra

You query should return all the columns in the select list once for each and every row that meets the specified join condition, how does this differ from what you are getting?
So if tableA is the student table with only one row per student you would expect to see the student data duplicated once for every matching course row found in tableB, and so on when tableC is added in.
If you need help please post partial results and then explain what results you want.
HTH -- Mark D Powell --
PS as sb mention you forgot your join condition to tableC which would multiply tableC by the other tables.
Edited by: Mark D Powell on Feb 3, 2010 9:18 AM

Similar Messages

  • [ADF Help] How to create a view for multiple tables

    Hi,
    I am using Jdeveloper 11G and ADF framework, and trying to create a view to update multiple tables.
    ex:
    Table A has these fields: ID, Name
    Table B has these fields: ID, Address
    A.ID and B.ID are primary keys.
    B.ID has FK relationship with A.ID
    (basically, these tables have one-to-one relation)
    I want to create a view object, which contains these fields: B.ID (or A.ID), A.Name, B.Address.
    So I can execute C,R,U,D for both tables.
    I create these tables in DB, and create entity objects for these tables.
    So there are 2 entity objects and 1 association.
    Then I create a view object based on B and add fields of A into the view:
    If the association is not a "Composition Association",
    when I run the model ("Oracle Business Component Browser") and try to insert new data, fields of A can't edit.
    If the association is a "Composition Association", and click the insert button, I will get
    "oracle.jbo.InvalidOwnerException: JBO-25030: Failed to find or invalidate owning entity"
    If I create a view object based on A and add filed of B into the view:
    When I run the model and try to insert new data, fields of B can't edit, no matter the association is or is not a composition association.
    So... how can I create a view for multiple tables correctly?
    Thanks for any advices!
    Here are some pictures about my problem, if there is any unclear point, please let me know.
    http://leonjava.blogspot.com/2009_10_01_archive.html
    (A is Prod, B is CpuSocket)
    Edited by: user8093176 on Oct 25, 2009 12:29 AM

    Hi Branislav,
    Thanks, but the result is same ....
    In the step 2 of creating view object, I can select entity objects to be added in to the view.
    If I select A first, and then select B (the "Source Usage" of B is A), then finishing the wizards.
    When I try to create a new record in the view, I can't edit any properties of B (those files are disabled).
    If I select B first, and then select A in crating view object, the result is similar ...
    Thanks for any further suggestion.
    Leon

  • HOW CAN I CREATE A VIEW FROM SAME TABLE WHERE I NEED COLUMNS DETAILS FROM DIFFERENT ROWS IN THE SAME TABLE

    i have a table1 on the top, but i want to create a view from table 1 as  view mentioned beneath the table 2. Could any of you please help me.
    table1
    ID
    office
    employee
    activity
    1
    246
    -9999
    698
    2
    ##-99
    21480
    698
    3
    104
    -9999
    7025
    4
    ##-99
    88908
    7025
    5
    108
    -9999
    2415
    6
    ##-99
    17135
    2415
    7
    246
    -9999
    698
    8
    ##-99
    21480
    698
    9
    104
    -9999
    7025
    10
    ##-99
    88908
    7025
    11
    108
    -9999
    2415
    12
    ##-99
    17135
    2415
    view
    ID
    office
    ID1
    employee
    activity
    1
    246
    2
    21480
    698
    3
    104
    4
    88908
    7025
    5
    108
    6
    17135
    2415
    7
    246
    8
    21480
    698
    9
    104
    10
    88908
    7025
    11
    108
    12
    17135
    2415

    declare @forumsTable table (ID int, officeID int, employeeID INT, activityID int)
    insert into @forumsTable (ID, officeID, employeeID, activityID)
    values
    (1 ,246, -9999, 698 ),
    (2 ,-99, 21480, 698 ),
    (3 ,104, -9999, 7025),
    (4 ,-99, 88908, 7025),
    (5 ,108, -9999, 2415),
    (6 ,-99, 17135, 2415),
    (7 ,246, -9999, 698 ),
    (8 ,-99, 21480, 698 ),
    (9 ,104, -9999, 7025),
    (10 ,-99, 88908, 7025),
    (11 ,108, -9999, 2415),
    (12 ,-99, 17135, 2415)
    select f1.ID, f1.officeID, f2.ID as ID1, f1.employeeID, f1.activityID
    from @forumsTable f1
    inner join @forumsTable f2
    on f1.activityID = f2.activityID
    and f1.officeID > 0
    and f2.employeeID > 0
    and f1.id - f2.id = -1
    You really need to improve the relationship here.
    Perhaps you could make office and activity an exclusive pair.

  • View from multiple tables

    Hi,
    I would like to create a view from 4 different tables. How do I do it?.
    Say for example, I need user_id from table A which has the trans_id in table B and C. and I need to get a admin_id from table D and show these related fields in one single row . I'm trying to create a view to achieve this.
    Pls help.
    Thanks,
    Ananth

    Are you asking how to write the SQL, or just how to define the view (which I guess is pretty much the same thing)?

  • Create object type from multiple tables for select statement

    Hi there,
    I have 3 tables as given below and I wish to create an object type to group selected columns as 'attribute' from multiple tables. 
    I need to create 2 input parameters to pass in - 'attribute' and 'attribute value'  in PL/SQL and these 2 parameters will be
    passing in with 'column name' and 'column value'.  e.g. 'configuration' - the column name, 'eval' - the column value.
    Then, the PL/SQL will execute the select statement with the column and column value provided to output the record. 
    Pls advise and thank you.
    table ccitemnumber
    name                           null     type                                                                                                   
    ccitemnumber                   not null varchar2(20)                                                                                                                                                                                    
    configuration                           varchar2(20)
    item_type                               varchar2(30)
    table productmodel
    productmodelnumber             not null varchar2(6)                                                                                            
    description                             varchar2(60)  
    accesstimems                            number                                                                                                 
    numberofheads                           varchar2(2)
    generation                              varchar2(10)
    numberofdiscs                           varchar2(2)
    factoryapplication                      varchar2(150)
    table topmodel
    stmodelnumber                  not null varchar2(30)                                                                                           
    productfamily                           varchar2(60
    formfactor                              varchar2(10)                                                                                           
    modelheight                             varchar2(10)                                                                                           
    formattedcapacity                       number                                                                                                 
    formattedcapacity_uom                   varchar2(20)
    object type in database
    configuration                           varchar2(20)
    item_type                               varchar2(30)
    numberofheads                           varchar2(2)
    generation                              varchar2(10)
    numberofdiscs                           varchar2(2)
    factoryapplication                      varchar2(150)
    modelheight                             varchar2(10)
    formattedcapacity                       number                                                                                                 
    formattedcapac

    user12043838 wrote:
    Reason to do this as these fields are required to be grouped together as they are created in different tables. They are treated as 'attribute' (consists of many columns) of the part number. So, the PL/SQL is requested to design in a way able for user to pass in the column name and column value or part number, then the select statement should be able to query for the records. Another reason is a new column can be added easily without keep modifying those effected programs. Reuseable too.This basically equates to ... hard to code, hard to maintain, and poor performance.
    Are you really sure you want to do this? This isn't going to be easy-street as you seem to think it is, but it's a one way street to a poorly performing system with security vulnerabilities (google SQL Injection).
    I would highly recommend you reconsider your design decision here.

  • Create a view from 10 tables

    Hi Experts,
    I want to create a view from 10 pricing tables rather than write 10 different select query in my application. Most of the columns of the pricing tables are same. I want all the data from these tables into the respective columns. Further I want an indicator as to which table does this record belong to. How can I achieve this?
    Ex:
    Table 1 columns: kappl kschl vkorg vtweg vkgrp
    Table 2 columns: kappl kschl vkorg vtweg matkl matnr
    if each table has two records, I want 4 records in my view in the respective columns along with the indicator that this record belongs to a specific column.
    Regards

    Hi,
    Placing 10 tables in one view will drastically affect performance. This is highly unrecommended.
    Anyhow if you insist on doing so you can create [database view|http://help.sap.com/saphelp_nw04/helpdata/en/36/74c0358373003ee10000009b38f839/frameset.htm] or use explicitly joins in your program.
    Keep in mind that althought it is possible to use projection (only selection of choosen column) it is not logically appropriate to locate which table this column belongs to (as far as we are talking about key fields) as both have the same field as key field.
    On the other hand when using projection for non-key columns it is you who define what is to be selected and how, therefore you know which column belongs to which table.
    i.e
    data: begin of st,
              lgart type t512w-lgart,
              molga type t512w-molga,
              lgtxt   type t512t-lgtxt,
            end of st.
    select w~molga w~lgart t~lgtxt   "<- here using aliases you know which column is taken from which table
      into st
      from T512W as W
      inner join T512T as T on
         W~LGART = T~LGART.
      write: / st-lgart, st-molga, st-lgtxt.
    endselect.
    In this example lgart (key field) can be taken from either t512w or t512t, but fields mogla and lgtxt are taken from t512w and t512t respectively.
    All in all this is correct as far as up to 3-4 tables are concerned. But 10 will be a disaster...
    Hope this helps you
    Marcin

  • Creat View from Multiple tables , Multiple Select

    Hello  Everyone ,
    I have a question and am not sure if this the correct forum to post it .
    I have two table studentTable and CourseTable which is each student  take more than one course . 1:M
    for example Student1 take 2 courses (C1 ,  C2).
    Student2 take 3 courses (C1,C2, C3).
    I need to create a table/View that contain student information plus all the courses and the score for each  course in one row.
    for example
    Row1= Student1_Id ,C1_code ,C1_name  ,C1_Score ,C2_code,C2_name ,C2_Score
    Row2=
    Student2_Id,C1_code,  C1_name,C1_Score,C2_code ,C2_name ,C2_Score ,  C3_code,C3_name,C3_Score
    and since Student 1 just took two courses  , I  should enter NULL in 'Course 3 fields'
    My Struggle is in the insert  statement
    I tried the following but it show an error
    Insert Into  Newtable
    ( St_ID, C1_code,c1_name, C1_Score ,C2_code  ,C2_name,C2_score,C3_code ,C3_name,C3_score)
    Select
    (Select St_ID from  StudentTable)
    (Select C_code,c_name,c_Score
    from  Coursetable,SudentTable
    where course.Stid =Studet.stid)
    (Select  C_code,c_name,c_Score
    from course ,student
    where course.Stid =Studet.stid  ),
    (Select C_code,c_name,c_Score
    from course ,student
    where  course.Stid =Studet.stid );
    I'm fully aware that the New table will break  the rules of normalization ,but I need it in this way for specifc purpose.
    I tried  also the PIVOT BY functionality but no luck with it .
    FYI , I'm not  expert in using SQL Syntax , I just know the basic.
    I will be great full for  any helpfull suggestions to try ,
    thank you very  much.

    First Table is Member table which Represent
    Students Information
    .The fields in this table are
    member_sk (PrimaryKey), full_or_part_time, gender, age_at_entry, age_band_at_entry, disability, ethnicity,
    widening_participation_level, nationality
    Second Table is Modules table which include
    the Courses' scores that Student took .
    The fields in this table are
    Module_result_k(Primary Key), member_sk(Foreign key to connect to Member table), member_stage_sk
    ,module_k(Foreign key to connect to Module table), module_confirmed_grade_src, credit_or_result
    Third Table is
    AllModuleInfo which is include
    general information for each course .The fields in this table are
    Module_k (Primary key), module_name ,module_code, Module_credit, Module stage.
    The New table
    that I will create has the following fields
    member_sk (PrimaryKey), full_or_part_time, gender, age_at_entry, age_band_at_entry, disability, ethnicity,
    widening_participation_level, nationality 
    " This will be retrieved from Member table"
    Also will include
    Module 1_name ,module1_code, Module1_credit, Module1_ stage, member1_stage_sk
    , module1_confirmed_grade_src, credit1_or_result
    Module 2_name ,module2_code, Module2_credit, Module2_ stage, member2_stage_sk
    , module2_confirmed_grade_src, credit2_or_result
    I will repeat this fields 14 times which is equal to Maximum courses number 
    that any of the students took.
    //// I hope now my questions become more clear

  • Problem in creating a view over multiple tables

    How do I create a View on top of the bCrelow tables. I have metioned the key fields of each table. How do i join the tables with common fields? I also need to create a Generic Extractor over the View later.
    Z3PVR ( Custom Z table ):
    Key Fields--> MANDT: Client; BUKRS: Company Code; WERKS: Plant; EBELN: Purchasing Document Number; ELNR: Accounting Document Number.
    BSEG ( Cluster Table ):
    Key Fields--> MANDT: Client; BUKRS: Company Code; BELNR: Accounting Document Number; GJAHR: Fiscal Year; BUZEI: Number of Line Item Within Accounting Document
    CKIS ( Transparent Table ):
    MANDT: Client; LEDNR: Ledger for Controlling objects; BZOBJ: Reference Object; KALNR: Cost Estimate Number for Cost Est. w/o Qty Structure; KALKA: Costing Type; KADKY: Costing Date (Key); TVERS: Costing Version; BWVAR: Valuation Variant in Costing; KKZMA: Costs Entered Manually in Additive or Automatic Cost Est.; POSNR: Unit Costing Line Item Number
    BKPF ( Transparent Table ):
    MANDT:Client; BUKRS: Company Code; BELNR: Accounting Document Number;
    GJAHR: Fiscal Year
    RV61A ( Structure ):
    No Key
    T001 ( Transparent Table ):
    MANDT:Client; BUKRS:Company Code

    Hi Chintai,
    To create a view you can use Tcode SE11.
    In the first screen of view creation you must introduce the tables for the view and the conditions of join, remember to introduce always the field MANDT.
    You are introducing too much tables in your view and if I am not wrong you can not introduce Structures in a view.
    As a suggestion start introducing in View only the tables that contain all char you need and also the tables with a reduced number of keys (as T001).
    You can then obtain other fields from other tables via CMOD.
    To built up a Generic extractor on this view you can use Tcode RSO2.
    You can find under www.service.sap.com/bi an How to doc on Generic DataSource creation.
    Ciao.
    Riccardo.

  • How to creat  Data source from Multiple Tables in   SAP  BI ?

    Hi Experts,
    1. For Finance & Payments MIS   tables are u2013   BSEG, BSIS,BSAS,PYAR ,BKPF
    2. For Inventory tables are           :           MSEG MKPF.
    3. For Invoices MIS   tables are  -          RBKP & RSEG.
    4. For Taxation MIS  tables  are u2013           J_1IEXCHDR, J_1IEXCDTL, J_1IPART2, J_1IPART1
    5. For Master data  tables  are   -    :         MARA, MAKT, LFA1, J_1IMTCHID
    How to creat   individual  Datasource  for   1.Finance & Payemnt Mis , 2. Inventory, 3. Invoices,  4. Taxation , 5. Mater data. ?

    Hi,
    Go for the generic data sources.
    1. first create the view on all the tables.
            You can only use join conditions but not Union.
            you can specify one table as primary table based on your requirement.
    2. build the data source based on the view.
    Regards,
    Siva
    Edited by: sivaramakrishna on Feb 2, 2012 3:54 PM

  • Microsoft Access 2010 Creating a Form from Multiple Tables

    Hi.
    I am brand new to Microsoft Access and have had some exciting success making forms from single tables. This has made my data entry life much easier. However, I am continually stumped on one form I want to make. I would like to make a form that will let me
    update which brands retailers are selling. Most of this information is in my SalesHx table. However, my SalesHx table only uses RetailerID and BrandID to record history. The Brand's name (linked to a BrandID) is stored in my Brand Table and the Retailer name
    is stored in my Retailer table (linked to a RetailerID). I would like to be able to see the brand's name and the retailer's name when entering in data on a form, since I cannot remember the ids that associate with the names. I have been able to make a form,
    with a subform, that displays all of the information I want to see. When I update this form, though, with a new record, it invariably thinks that I am adding an entirely new record, not simply recording a new sales date for an already known brand. Even if
    I make the brand name a combo box that is limited to the fields on my table, this still happens. I will have BrandX as brand number 100 and as brand number 300 if I add it in through my sales history form. I am ready to throw access out the window. Can anyone
    offer advice?

     When I update this form, though, with a new record, it invariably thinks that I am adding an entirely new record, not
    simply recording a new sales date for an already known brand. 
    In what table is the SalesDate recorded?
    Build a little, test a little

  • Creating a list from multiple tables

    Hi!
    Hopefully someone can help. I have a spreadsheet with 9 tables on it. I use this sheet to track different groups of volunteers based on departments. I have a separate table for each department. The  first table has a list of all of the volunteers. I currently fill in the names from each table on the the first table manually. I would like to be able to type a name into one of the tables and it auto populate on the first table. Is this possible or asking too much?
    Thanks for any help you can give me!

    Hi J,
    Turning the problem on its head, here is one approach. Start with two tables.
    The Department table is one cell. It will act as the trigger to filter rows in the Volunteers table.
    The Volunteers table contains the names of all volunteers. The order of names is alphabetical, but that may not be important in your aim. Column B contains dummy values for each Department.
    In the Volunteers table, select cells B2 to the bottom of the table. Format them as Pop-Up Menu.
    Delete Row 2 (it won't remove "All" from the Pop-Ups).
    Select and copy cell B2 and paste into the Department table so that it too becomes a Pop-Up.
    Using the Pop-Ups in the Volunteers table, assign a department to each volunteer:
    Now to set up Column C for the filter.
    Formula in C2 (and Fill Down) is:
    =IF(Department::A$1="All","Show",IF(B2=Department::A$1,"Show",""))
    Now select something other than All in the Department table
    Filter Rule on Column C ("Show"):
    To see this:
    You can hide columns B and C.
    To see the full list of volunteers again, choose All in the Department table
    Regards,
    Ian.
    Acknowledgment to t quinn for showing this filter idea in another thread. Ian.

  • Crate view from multiple tables in mysql

    does anybody know what the correct syntax is?
    I need to do the following:
    create view myView as select * from tOne, tTwo, tThree;this does not work in mysql. How this can be done?
    thanks

    You need to be using a version of MySQl that supports views, 5.0 or greater. This SQL will tell you which version you are using:
    SELECT version();The tables also need to exist prior to the creation of the view.
    Otherwise, that syntax should work...
    http://dev.mysql.com/doc/refman/5.0/en/create-view.html

  • Creating a datablock from multiple tables

    Hi
    I have a situation in which. There are two tables with the same set of columns and same names. when creating a block ,rows from both these tables have to populated into Form.
    (for example... One table represents expired details and the other one with valid details)
    Form accepts runtime parameters and displays the records. Any idea how to solve this. Please offer your suggestions
    Thanks
    null

    As ivar said if u create view and use then u cant update the values. One alternate solution is do manually. First of all why do u need to put both the base tables in a single block. Create 2 blocks corresponding to two expired and valid base tables. You can very well display both the information from 2 blocks in the same Form. Just get the user input and query manually. When u create two base table blocks Oracle will take care of the querying/inserting values from tables though both might have same column names. I hope this helps.

  • Create view from multiple days tables

    Hi,
    I'm having existing oracle db with daily stat data, tables strangely named data_mon, data_tue, data_wed.. For my batch processing I plan to use view with multiple day data, let say for last 5 days.
    Not sure how better implement my sql statement, with those _mon suffixes to make it more or less dynamic.
    I also never create View from multiple tables, so probably I can do something that will add fresh daily data and delete 5 days old data?
    Will appreciate you comments on details and whole concept. I have prev sql server experience.
    Thanks
    T

    user12943718 wrote:
    Hi,
    I'm having existing oracle db with daily stat data, tables strangely named data_mon, data_tue, data_wed.. For my batch processing I plan to use view with multiple day data, let say for last 5 days.
    Not sure how better implement my sql statement, with those _mon suffixes to make it more or less dynamic.
    I also never create View from multiple tables, so probably I can do something that will add fresh daily data and delete 5 days old data?
    Will appreciate you comments on details and whole concept. I have prev sql server experience.
    Thanks
    TChange the data model so you don't have 1 table for a day.
    You just have a DATA table, and a column to denote the day of applicability.
    Then you don't need a view, don't need anything dynamic, don't need to smash your head against a wall for a simple query ... etc.

  • Is selecting from a view more efficient than selecting from multiple tables

    Hi heres the problem
    Lets say i created a view from 2 tables (person and info). both have a ID column
    create view table_view (age,name,status,id) as
    select a.age, a.name, b.status, b.id
    from person a, info.b
    where a.id=b.idif i want to select a given range of values from these 2 tables which of the following queries would be more effective.
    select a.age, a.name, b.status, b.id
    from person a, info.b
    where a.id=b.id
    and a.id <1000
    select age, name, status, id
    from table_view
    where  id <1000

    Bear in mind that this concept of views storing the SQL text is something relative to Oracle databases and not necessarily other RDBMS products. For example, Ingres databases create "views" as tables of data on the database and therefore there is a difference between selecting from the view and selecting from the base tables.
    Oracle also has "materialized views" which differ from normal "views" because they are actually created, effectively, as tables of data and will not use the indexes of the base tables.
    In Oracle, you cannot create indexes against "views" but you can create indexes against "materialized views".

Maybe you are looking for

  • Need Help in tuning this query

    select CO_PROFILE.CO_NO AS "UEN No.", CO_PROFILE.CO_NAME AS "Entity Name", DECODE(CO_PROFILE.CO_TYPE,'A1','PUBLIC COMPANY LIMITED BY SHARES', 'A3','COMPANY LIMITED BY GUARANTEE', 'A4','UNLIMITED PUBLIC COMPANY', 'B1','LIMITED PRIVATE COMPANY', 'B2','

  • Trying to install my elements 12 on my laptop-cant find the download page

    Trying to install my elements 12 on my laptop, can't find the download page

  • My ipod classic 160gb has frozen. Any ideas how to un-freeze

    My ipod classic 160gb has frozen. Can anyone help me to un-freeze it?

  • Using A5 or custom size paper

    I need to print photographs on A5 paper, but Photoshop CS6 (64 bit) doesn't give me the option to use that paper size, nor do I have the option to set up a customised paper size for my printer.  I'm printing on a Canon MG6250.  Photoshop is installed

  • Receiving error message 2894

    I have tried to download itunes from the website. An error message pops up stating that installation cannot be completed error 2894. I have looked at other topics and questions but did not see anything related to that error message. I'm a new ipod us