DBAsupport.com Forums - Powered by vBulletin
Results 1 to 7 of 7

Thread: join

  1. #1
    Join Date
    Jun 2002
    Posts
    15
    Hello,

    i have two tables tbl_hs and tbl_st and there are fields in tbl_hs like: hs_id, hs, name and so on. and in tbl_st there are fields like st_id, st_name and so on.

    None of the tables have not been defined with keys

    Now, can i fetch records from these two tables???if so, how can i do that.

    thanking you


  2. #2
    Join Date
    Jan 2002
    Location
    Up s**t creek
    Posts
    1,525
    Yes you can join the tables, by simply using a where clause e.g.

    select a.id, a.name, b.address
    from names a, addresses b
    where a.id = b.name_id

    I think you need to give a bit more detail on what your trying to do.

    Regards
    Jim
    Oracle Certified Professional
    "Build your reputation by helping other people build theirs."

    "Sarcasm may be the lowest form of wit but its still funny"

    Click HERE to vist my website!

  3. #3
    Join Date
    Jun 2002
    Posts
    15
    well,i tried and i could'nt get it.
    Here goes.......

    tbl_hs
    --------
    hs_id
    hs_name
    hs_add
    hs_zip

    tbl_st
    ---------
    st_id
    st_name
    st_tel
    st_fax

    Now, i want to get the data from the above two tables.

    I want to get these fields:hs_name,hs_add, hs_zip,st_tel and st_fax.

    How can i write the select statement??

    Many thanks

  4. #4
    Join Date
    Jan 2002
    Location
    Up s**t creek
    Posts
    1,525
    What is the entity between the two tables? for a join to exist there must be some linking entity such as an id, name, etc.

    For example if the hs_id and st_id entities are common the query would be:

    select a.hs_name, a.hs_add, a.hs_zip, b.st_tel, b.st_fax
    from tbl_hs a, tbl_hs b
    where a.hs_id = b.st_id;

    if it was the name column the query would be:

    select a.hs_name, a.hs_add, a.hs_zip, b.st_tel, b.st_fax
    from tbl_hs a, tbl_hs b
    where a.hs_name = b.st_name;

    Hope that helps

    Regards
    Jim
    Oracle Certified Professional
    "Build your reputation by helping other people build theirs."

    "Sarcasm may be the lowest form of wit but its still funny"

    Click HERE to vist my website!

  5. #5
    Join Date
    Jun 2002
    Posts
    15
    hi jim,
    whatz a and b :-/

    Therez no relation between these two tables?aint it possible to get those records?


  6. #6
    Join Date
    Jan 2002
    Location
    Up s**t creek
    Posts
    1,525
    The a and b are just table aliases.

    In order to have a join you have to have a common entity, otherwise how will you know which record relates to another in an additional table. The join does not have to be enforced but you have to have commonality.

    if rows where inserted into both tables at the same time then you might be able to use the row number.

    Regards

    [Edited by jovery on 06-21-2002 at 08:49 AM]
    Jim
    Oracle Certified Professional
    "Build your reputation by helping other people build theirs."

    "Sarcasm may be the lowest form of wit but its still funny"

    Click HERE to vist my website!

  7. #7
    Join Date
    Jun 2002
    Posts
    15
    Jim, is that possible to retrieve the data by using two select statements?

    Or, if by enforcing some keys on the fields, how can i do that?

    Thanks

Posting Permissions

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


Click Here to Expand Forum to Full Width