En mulig løsning ville være først at oprette en forespørgsel for hver type reservation (som du måske allerede har) og tilføje cust_type der og derefter forene de to sammen. Så de indledende forespørgsler ville være noget i stil med:
gæstereservationer:
SELECT reservation.r_id, guest.name, "guest" AS cust_type, {other fields}
FROM guest, reservation INNER JOIN guest ON guest.g_id = reservation.g_id;
company_reservations:
SELECT reservation.r_id, company.name, "company" AS cust_type {other fields}
FROM company, reservation INNER JOIN company ON company.c_id = reservation.c_id;
Så kan du forene de to forespørgsler sammen, noget som nedenfor.
SELECT reservation.r_id, guest.name, "guest" AS cust_type, {other fields}
FROM guest, reservation INNER JOIN guest ON guest.g_id = reservation.g_id
UNION SELECT reservation.r_id, company.name, "company" AS cust_type {other fields}
FROM company, reservation INNER JOIN company ON company.c_id = reservation.c_id;
Husk selvfølgelig enten at fjerne {other fields} eller tilføje hvad du ellers har brug for der.