Join Query Help
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
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.
SELECT * FROM table1 WHERE pid = 21
SELECT * FROM table2 WHERE pid = 21
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.
Thank u very much mate....actually i thought of using UNION also....but didnt used it...now i'll go through it..
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)