I have four tables in the database, that is, packages, fixtures, offers and offers.
Here are the details of the table structure:
Packages: id, title
Fixtures: id, package_id, name
Deals: id, discound, description
Fixtures_Deal: id, fixture_id, deal_id, price
I need to get a list of packages along with the minimum transaction price offered in each device for each package.
Here is the mysql query that I run in phpMyAdmin or SQLYog and it works fine, but in Laravel it gives me the error "p.title" not in GROUP BY.
SELECT
p.title AS package_title,
tbl_min_value.min_price AS min_price
FROM
(SELECT
fixture_id,
MIN(deal_price) AS min_price
FROM
fixture_deal
GROUP BY fixture_id) AS tbl_min_value
JOIN fixtures AS f
ON f.id = tbl_min_value.fixture_id
RIGHT JOIN packages AS p
ON f.package_id = p.id
GROUP BY p.id
By the way, I am trying to achieve this using the following method in the model:
return DB::statement('SELECT
p.title AS package_title,
tbl_min_value.min_price AS min_price
FROM
(SELECT
fixture_id,
MIN(deal_price) AS min_price
FROM
fixture_deal
GROUP BY fixture_id) AS tbl_min_value
JOIN fixtures AS f
ON f.id = tbl_min_value.fixture_id
RIGHT JOIN packages AS p
ON f.package_id = p.id
GROUP BY p.id');