Results 1 to 3 of 3

Thread: Join Query Help

  1. #1
    Join Date
    Dec 2010

    Join Query Help

    Hey Guys,

    Am in a situation, where i'm having two tables and a value from a text box (Say an patient id no:'21') which will be either in these two tables..so i need to check the two tables for the patient id no:'21' and retrieve the details of the patient id.i'm running out of ideas for this simple query..pls help as im newbie for this.

    my tried query will be like this(select table1.*,table2.* where table1.pid='21' or table2.pid='21')Note:'21' will be the dynamic value from textbox ...i dont no this query is right...pls help

  2. #2
    Join Date
    Dec 2002
    St. Louis, MO, USA
    SELECT * FROM table1 WHERE pid = 21
    SELECT * FROM table2 WHERE pid = 21
    The downside to this is that if both tables have an id of 21, both tables will return the associated records. But if there is only ONE table with an id of 21, this will retrieve that one.

    Also, unless the ID is in a column of datatype char/varchar/nchar/nvarchar/text etc, you shouldn't need the apostrophe around 21; int/tinyint/bigint etc aren't strings.
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long


  3. #3
    Join Date
    Dec 2010
    Thank u very much mate....actually i thought of using UNION also....but didnt used it...now i'll go through it..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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