View Full Version : Validation based on information from two tables


atksamy
11-02-2008, 10:59 PM
hi,

I have two tables like the following:

table1

id variable
1 speed
2 distance
3 acceleration

table2

id allowedvalue
1 3
1 5
1 6
2 4
2 5


i want to write a a loop to check whether for a given variable in all tables in the database the values is within the allowed value. THe link for getting the allowed values of each table is the id no.
I think a join has to be made but i am not sure of how to go about it

thanks

WayPay
11-03-2008, 11:59 AM
Try this:
SELECT Table1.id, Table1.Variable
FROM Table1 LEFT JOIN Table2 ON Table1.id = Table2.id
WHERE Table2.id IS NULLThis will give you all invalid variable values in Table1.