Validation based on information from two tables

atksamy

New member
Local time
Today, 12:25
Joined
Oct 24, 2008
Messages
2
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
 
Try this:
Code:
SELECT Table1.id, Table1.Variable
FROM Table1 LEFT JOIN Table2 ON Table1.id = Table2.id
WHERE Table2.id IS NULL
This will give you all invalid variable values in Table1.
 

Users who are viewing this thread

Back
Top Bottom