I have a table like
tbl_scripts
script_unique_id | system_id | script_name
+-----------------------------------------+
12345 | 89784 | Demo
And another table goes as
tbl_allowed_group_ids
system_id | script_unique_id |allowed_group_id
+---------------------------------------------+
89784 12345 56987
So now what I want is the row from tbl_scripts with group_id only if the unique id is in allowed_group_id
What I tried is this but is nowhere close to it….I know this is completely wrong
SELECT script_name FROM tbl_scripts WHERE script_unique_id = allowed_group_id
You will want to
JOINthe tables:See SQL Fiddle with Demo
If you need help learning join syntax, here is a great visual explanation of joins.
A
LEFT JOINwill return all rows in thetbl_scriptstable regardless of whether or not it has a matching row in thetbl_allowed_group_idstable. If you only want matching rows, then you can use anINNER JOIN