Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2004
    Posts
    4

    Unanswered: Can I get a row with a single query?

    I have two tables with an identifying (1:0-N) relationship between the parent and child tables. Is there a way I can do a single select query to get a row from the child table? To me it seems that I must do two queries, one to get the id from the parent table and then another using that id to query the child table.

  2. #2
    Join Date
    Aug 2004
    Posts
    330
    Yes there is. A Join or a Subselect will work.

  3. #3
    Join Date
    Dec 2004
    Location
    Apeldoorn, the Netherlands
    Posts
    9
    select B.[the column you want]
    ,A.[another column you want]
    from parent_table A
    ,child.table B
    where A.ID = B.ID
    and...
    /

    Dunno what you mean really.
    the above example joins the two tables on ID.
    When that's done, you can select what you want from it.

  4. #4
    Join Date
    Dec 2004
    Posts
    12
    hi u can just use a subquery to get what u want.
    example
    select * from child_table
    where id =(select * from parent_table where id1=<value>)

    the subquery will return a vlue from the parent table which will be passed into the main query.
    i guess this should help.

  5. #5
    Join Date
    Nov 2004
    Location
    Temple University
    Posts
    36

    Cool

    To answer the question correctly, NO. You can not limit the query to just one row, because there may be multiple rows in the child table, ALL of which will be returned.

    HTH
    Peter

  6. #6
    Join Date
    Aug 2004
    Posts
    330
    In another way, the answer to the question is YES. Because you can get A ROW. You may not ALWAYS get A ROW, and you might get A ROW and some other rows, but you "can do a single select query to get a row from the child table".

Posting Permissions

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