SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    India
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    prob in retrieving

    i have two tables named sec_mast and sec_detail

    SQL> descr sec_mast;
    Name Null? Type
    ----------------------------------------- -------- ------------
    SEC_NO NOT NULL NUMBER(4)
    CATG_CODE NUMBER(2)
    FACE_VAL NOT NULL NUMBER(10,2)
    PUR_VAL NOT NULL NUMBER(10,2)
    INT_PAID NOT NULL NUMBER(8,2)
    INT_RECD NOT NULL NUMBER(8,2)
    BRKR NOT NULL NUMBER(8,2)
    TOT_VAL NOT NULL NUMBER(12,2)
    VOU_NO VARCHAR2(9)
    VOU_DATE DATE
    VOU_AMT NUMBER(15,2)
    DUE_DATE1 NOT NULL DATE
    DUE_DATE2 DATE
    LF_NO NOT NULL VARCHAR2(10)
    MAT_DATE NOT NULL DATE
    FK_VOU_NO2 VARCHAR2(9)

    SQL> descr sec_detail;
    Name Null? Type
    ----------------------------------------- -------- ----------------
    SEC_NO NUMBER(4)
    LF_NO VARCHAR2(8)
    DUE_DATE1 DATE
    VOU_NO VARCHAR2(9)
    VOU_DATE DATE
    VOU_AMT NUMBER(15,2)
    FK_VOU_NO1 VARCHAR2(9)


    my problem is that i want to retrieve values from database and i have used following query for the prepared statement.Here VOU_No is foreign key.

    select * from sec_detail,sec_mast where sec_detail.sec_no=sec_mast.sec_no //

    if this query is wrong then plzz help me in this..

  2. #2
    SitePoint Member
    Join Date
    Dec 2004
    Location
    in my mind. well, physically in the Bay Area
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    more info please

    hi,
    r u in bangalore? i hope you are alright and not in the south experiencing the chaos brought about by the tsunami. about your post, can you provide a little more info- i'm unclear on what info you are trying to get from these tables. you said > Here VOU_No is foreign key.
    but this column is in both tables.

    so i will make a few assumptions to begin with and we can go from there.
    1: sec_detail.vou_no is a foreign key to the primary key of table sec_mast
    2: sec_mast.sec_no is the primary key of that table
    3: you want to get records in sec_detail that correspond to sec_mast
    then you need to join those two fields- not the two primary keys.
    try:
    select * from sec_mast
    inner join sec_detail on sec_detail.VOU_no=sec_mast.sec_no

    OR, if vou_no is a foreign key in both those tables to a third table, then query on that column matching:
    select * from sec_mast
    inner join sec_detail on sec_detail.vou_no=sec_mast.vou_no

    let me know if this does not get the results you want...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •