I have what will end up being a complex query where certain parts will often be repeated. I would therefore like to store the results of some sub queries into variables which can then be used in the main query.
For example I would like to set the variable 'variable_id' to be equal to a SELECT query and variable_school_id to be equal to another SELECT query:
variable_id integer := (SELECT id FROM account WHERE email = '[email protected]');
variable_school_id integer := (SELECT school FROM account WHERE email = '[email protected]');
Then I would like to make use of those variables in a query that would look like:
select * from doctor where account_id = variable_id AND school = variable_school_id ;
How do I go about doing this?