I have two tables:
table 1 : info1 -> where i have pid(primary key),name,address,sex etc.
table 2 : visit -> where i have the pid(foreign key), visit_date,next_visit,details
I used a query
SELECT info1.Patient_ID, visit.Visit_Date, visit.Next_Visit,
visit.Visit_Details from info1, visit WHERE info1.Patient_ID ="%"
Is this query correct??
Your query needs a JOIN
:
SELECT info1.Patient_ID, visit.Visit_Date, visit.Next_Visit, visit.Visit_Details
FROM info1 INNER JOIN visit ON info1.Patient_ID = visit.Patient_ID
WHERE info1.Patient_ID ="%"
If you use an INNER JOIN
as shown above, then you'll only get a result for Patient_ID's that have an entry in both of the two tables. If you wanted to see all Patient_ID's whether or not they had a visit
record, for example, you would use a LEFT OUTER JOIN
.
Note: in the LabVIEW code you've shown, you are constructing the query by building a string from user-supplied data (the Patient ID
front panel control). This is a really bad idea because it enables SQL injection attacks by malicious users. You should look up how to supply the value as a parameter to your LabVIEW database functions instead.