0

So.. I've got:

3 DB Queries returning 1 row each ....

SELECT value FROM ja_settings WHERE varname='clickatel_api_id' 
SELECT value FROM ja_settings WHERE varname='clickatel_user' 
SELECT value FROM ja_settings WHERE varname='clickatel_pass'

Could be re-written as:

SELECT value, 'clickatel_api_id' AS name FROM ja_settings WHERE varname='clickatel_api_id'
UNION ALL
SELECT value, 'clickatel_user' AS name FROM ja_settings WHERE varname='clickatel_user'
UNION ALL
SELECT value, 'clickatel_pass' AS name FROM ja_settings WHERE varname='clickatel_pass' ;

1 db query that returns 3 rows ... (there's even better ways than a union... I know). This would eliminate 2 db server roundtrips on ALL pages.

How could I write this Query? Thank you!

  • Why would union take three round-trips? Also, using UNION ALL won't guarantee you 3 rows. If you have duplicate results, you will get 4 or more results. – dizzystar Jan 7 '16 at 4:04
6

I guess you want something like this:

SELECT value, varname
FROM ja_settings 
WHERE varname IN ('clickatel_api_id', 'clickatel_user','clickatel_pass');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy