I have 2 tables I need to query with similar contents but differing field names.
I’m wanting to merge the following 2 queries into 1 so that I have 1 set of results.
The 2 queries are:
SELECT
bookings.booking_name,
bookings.booking_email,
bookings.booking_mobile
FROM
bookings
WHERE
( bookings.booking_email LIKE "%' . $_POST['val'] . '%"
OR
bookings.booking_name LIKE "%' . $_POST['val'] . '%"
OR
bookings.booking_mobile LIKE "%' . $_POST['val'] . '%"
)
SELECT
purchases.customer_name,
purchases.customer_email,
purchases.customer_phone
FROM
handbags
WHERE
( purchases.customer_email LIKE "%' . $_POST['val'] . '%"
OR
purchases.customer_name LIKE "%' . $_POST['val'] . '%"
OR
purchases.customer_phone LIKE "%' . $_POST['val'] . '%"
)
How is this sort of thing accomplished so that in my result customer_email and booking_email can be accessed simply by ’email’.
Combine the two queries with the UNION operator, and give the columns matching names.