Swapnil Yeole February 2016

How can I convert below mysql query to laravel query builder

SELECT SQL_CALC_FOUND_ROWS * FROM ( (SELECT 1 AS orderField, mem.fname, mem.lname, mem.profilenam, mem.mem_id, mem.photo, mem.ethnicity, mem.profile_type, mem.gender, mem.verified, mem.deleted FROM members AS mem INNER JOIN network AS net ON net.frd_id = mem.mem_id WHERE net.mem_id= '1728' AND (mem.profilenam LIKE '%abc%' OR lname LIKE 'abc%' OR CONCAT(fname, ' ', lname) LIKE 'abc%') ) UNION (SELECT 2 AS orderField, fname, lname, profilenam, mem_id, photo, ethnicity, profile_type, gender, verified, deleted FROM members WHERE (profilenam LIKE '%abc%' OR lname LIKE 'abc%' OR CONCAT(fname, ' ', lname) LIKE 'abc%') ) ) AS t WHERE t.verified='Y' AND t.mem_id NOT IN (1,2,3,4,5,1728) AND t.deleted='N' GROUP BY t.mem_id ORDER BY t.orderField,t.profilenam DESC 0,50

Answers


mazedlx February 2016

DB::statement("SELECT SQL_CALC_FOUND_ROWS * FROM ( (SELECT 1 AS orderField, mem.fname, mem.lname, mem.profilenam, mem.mem_id, mem.photo, mem.ethnicity, mem.profile_type, mem.gender, mem.verified, mem.deleted FROM members AS mem INNER JOIN network AS net ON net.frd_id = mem.mem_id WHERE net.mem_id= '1728' AND (mem.profilenam LIKE '%abc%' OR lname LIKE 'abc%' OR CONCAT(fname, ' ', lname) LIKE 'abc%') ) UNION (SELECT 2 AS orderField,  fname,  lname,  profilenam,  mem_id,  photo, ethnicity,  profile_type,  gender,  verified,  deleted FROM members WHERE (profilenam LIKE '%abc%' OR lname LIKE 'abc%' OR CONCAT(fname, ' ', lname) LIKE 'abc%') ) ) AS t WHERE t.verified='Y' AND t.mem_id NOT IN (1,2,3,4,5,1728) AND t.deleted='N' GROUP BY t.mem_id ORDER BY t.orderField,t.profilenam DESC 0,50");

Post Status

Asked in February 2016
Viewed 2,631 times
Voted 5
Answered 1 times

Search




Leave an answer