如何将2个查询数据包含在单个结果中?

时间:2016-10-27 10:45:45

标签: php mysql

我有2个像这样的查询

查询1

        $this->db->select('*');
    $this->db->from('transaction_log');
    $this->db->join('crs_hotel_booking_details', 'transaction_log.app_reference = crs_hotel_booking_details.app_reference');
    $this->db->join('crs_hotel_supplier_details', 'crs_hotel_booking_details.hotel_id = crs_hotel_supplier_details.hotel_id');
    $this->db->join('crs_supplier_login', 'crs_supplier_login.supplier_id = crs_hotel_supplier_details.supplier_id');
    $this->db->where('crs_supplier_login.supplier_id',$this->entity_user_id);
    $query = $this->db->get();

查询2

    $this->db->select('*');
    $this->db->from('transaction_log');
    $this->db->join('service_booking_details', 'transaction_log.app_reference = service_booking_details.app_reference');
    $this->db->join('crs_service_supplier_details', 'service_booking_details.service_apartment_id = crs_service_supplier_details.service_apartment_id');
    $this->db->join('crs_supplier_login', 'crs_supplier_login.supplier_id = crs_service_supplier_details.supplier_id');
    $this->db->where('crs_supplier_login.supplier_id',$this->entity_user_id);
    $query = $this->db->get();

我在两个查询中都获得了值。请告诉我如何添加这两个查询

2 个答案:

答案 0 :(得分:0)

就像,

array_merge($query1->result_array(), $query2->result_array());

答案 1 :(得分:0)

SQL具有UNION子句,该子句从两个或多个SELECT语句返回单个结果集。