how to get the data from table with join

Discussion in 'Databases' started by dineshsingh1984, Jun 2, 2011.

  1. #1
    I'm created two table first one is test1 and second one is test2.
    In first table one field is id and in second table one field is id.
    in first table two data/value insert 1 and 2 and second table four data/value insert 1, 2, 3 and 4

    I want to acess only 3 and 4 data with use join key

    how can do this???????????
    plz help me.....................
     
    dineshsingh1984, Jun 2, 2011 IP
  2. bunty18

    bunty18 Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi friends i am bunty & i thinks an internet is a big & broad way to get our solution about any kind of problem in daily life :)
     
    bunty18, Jun 3, 2011 IP
  3. tothemax

    tothemax Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    do you mean like this?
    select table1.*, table2.* where table1.id=table2.id and table2.id in (3,4)
     
    tothemax, Jun 6, 2011 IP
  4. dineshsingh1984

    dineshsingh1984 Active Member

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    yes some thing like this but in case here its database content which are not static.

    I want to select only these data which are not available in other table

    In case i can't define like
    select table1.*, table2.* where table1.id=table2.id and table2.id in (3,4)

    because 3 and 4 is not static its changeable
    then how can retrive data ????????????

    plz reply me
     
    dineshsingh1984, Jun 16, 2011 IP
  5. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #5
    You need a left join and then a WHERE clause to find those that are null in the second table. Something like:

    SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id WHERE table2.id = NULL

    I haven't tested that SQL out, so there might be a syntax error or two, but that's the general idea of how you find all the records in one table without matches in the second.
     
    plog, Jun 20, 2011 IP
  6. amkeabhi123

    amkeabhi123 Member

    Messages:
    219
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #6
    select * from table t1 join table2 t2 as t1.id==t2.id ;
    can fetch the data in the table.
     
    amkeabhi123, Jun 21, 2011 IP
  7. unknownpray

    unknownpray Active Member

    Messages:
    3,831
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    70
    #7
    The JOIN keyword is used in an SQL statement to query data from two or more tables, based on

    a relationship between certain columns in these tables.
    if both the tables haved some same columns then we can combine them
    if we r having two tables then we can combine them as
    example:
    SELECT column_name(s)
    FROM table_name1
    INNER JOIN table_name2
    ON table_name1.column_name=table_name2.column_name
     
    unknownpray, Jun 24, 2011 IP
  8. shikhasweetie

    shikhasweetie Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    google is the best option to find the answer
     
    shikhasweetie, Jun 25, 2011 IP