SQL join 2 queries
Posted on 2011-02-20
Table 1: members
Fields: "id", "ug_school_id", etc
Table 2: tags
Tthe following sql queries are generated based on user input (database query script) - so it is preferred that the solution works with the existing $sql1/$sql2 variables.
$sql1 = "SELECT id FROM members WHERE 1=1 AND alumni = '1' AND ug_school_id = '7'";
$sql2 = "SELECT uid FROM tags WHERE 1=0 OR (ttype = 'hometown' AND tag = 'Cambridge, MA')";
All I want to do, is generate a table of results which shows the member rows which match in both these tables.
And also generate an extra temporary column in that results set for the 'hometown' data
E.g. if a member is an alumni and school id is 7 and hometown is Cambridge, MA
Many thanks in advance