Wanjala Alex Wanjala Alex - 3 years ago 111
MySQL Question

Combine SQL statement

I would like to select different column from different row from the same table with one statement . How will I combine this to be one?

SELECT `shop_lat_log` FROM `customers` WHERE `phoneNumber`='254719401837'
SELECT `delivery_lat_log` FROM `customers` WHERE `phoneNumber`='25472054919'

Answer Source

You could just use each of two current queries as subqueries in one select statement:

    (SELECT shop_lat_log FROM customers WHERE phoneNumber = '254719401837') AS shop_lat_log,
    (SELECT delivery_lat_log FROM customers WHERE phoneNumber = '25472054919') AS delivery_lat_log
FROM dual;

This assumes that each of your two queries returns a single value. If not, then perhaps a UNION would be more appropriate:

    shop_lat_log AS log_value,
    'shop_lat_log' AS log_type
FROM customers
WHERE phoneNumber = '254719401837'
FROM customers
WHERE phoneNumber = '25472054919'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download