mysql - Laravel: Is it possible to do a union query with Fluent or Eloquent? -


i have complex union query translate ms sql mysql using either laravel's fluent query builder or eloquent (just guessing fluent handle it). other alternative db raw query, doesn't seem laravelish.

i part of recurring events engine connect past events history table futures table holds recurrence pattern. here's query if you're interested.

qry = "select clients.p_client_id,contacts.last_name, contacts.first_name, " qry = qry & "resource_information.last_name res_last_name, resource_information.first_name res_first_name, " qry = qry & "assets.d_name, " qry = qry & "services.service_name, "  qry = qry & "service_recurring.id, service_recurring.client_id, service_recurring.partner_id, " qry = qry & "service_recurring.asset_id, service_recurring.resource_id, service_recurring.service_id, " qry = qry & "service_recurring.begin_on, service_recurring.window_beg, " qry = qry & "service_recurring.window_end, service_recurring.rate, " qry = qry & "service_recurring.discount, service_recurring.res_cost, service_recurring.recurring, service_recurring.id schedule_id  " qry = qry & "from service_recurring " qry = qry & "inner join clients on service_recurring.client_id = clients.id " qry = qry & "inner join contacts on service_recurring.client_id = contacts.client_id " qry = qry & "and contacts.primary_contact = 1 " qry = qry & "inner join assets on service_recurring.asset_id = assets.id " qry = qry & "inner join resource_information on service_recurring.resource_id = resource_information.id " qry = qry & "inner join services on service_recurring.service_id = services.id " qry = qry & "where service_recurring.partner_id = '" & partner_id & "' " qry = qry & "and not exists (select * service_recurring_exception rid = service_recurring.id , exception_date = '" & thisdate & "' , pid = '" & partner_id & "') " qry = qry & "and service_recurring.begin_on <= '" & thisdate & "' " qry = qry & "and (service_recurring.end_on >= '" & thisdate & "' or service_recurring.end_on null) " qry = qry & todayis qry = qry & "union " qry = qry & "select clients.p_client_id,contacts.last_name, contacts.first_name, " qry = qry & "resource_information.last_name res_last_name, resource_information.first_name res_first_name, " qry = qry & "assets.d_name, " qry = qry & "services.service_name, " qry = qry & "service_history.id, service_history.client_id, service_history.partner_id, " qry = qry & "service_history.asset_id, service_history.resource_id, service_history.service_id, " qry = qry & "service_history.begin_on, service_history.window_beg, " qry = qry & "service_history.window_end, service_history.rate, " qry = qry & "service_history.discount, service_history.res_cost, service_history.recurring, service_history.id schedule_id  " qry = qry & "from service_history " qry = qry & "inner join clients on service_history.client_id = clients.id " qry = qry & "inner join contacts on service_history.client_id = contacts.client_id " qry = qry & "and contacts.primary_contact = 1 " qry = qry & "inner join assets on service_history.asset_id = assets.id " qry = qry & "inner join resource_information on service_history.resource_id = resource_information.id " qry = qry & "inner join services on service_history.service_id = services.id " qry = qry & "where service_history.begin_on = '" & thisdate & "' , service_history.partner_id = '" & partner_id & "' " qry = qry & "and service_history.delete_r <> 1 " qry = qry & "order res_last_name, d_name" 


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -