I want to select specific columns based on a value of one column.
Currently, what I do is get the value of a specific column and use it to make another query. Like this:
SELECT service_type FROM agreements WHERE id = 1;
I'll pass the value to a PHP variable and make another query based on the result.
Sample code:
if (service == 'internet')
SELECT ipreq, latency, ... FROM agreements WHERE id = 3 AND service_type = 'internet';
else
SELECT rates, markup, ... FROM agreements WHERE id = 3 AND service_type = 'vpn';
Is there a way to do this without resorting to making multiple queries?
P.S.
Some of the columns comes from another table. I just want to select the specific columns from specific tables based on the value of a column (in this case, the service_type)