Reputation: 3
I test with mysql it work, but when I used Oracle, this error appear:
ORA-00979: not a GROUP BY expression
Here is my code:
<?php
$sqlSelect = "SELECT * FROM policy order by policyprogress_id asc";
if (isset($_GET['batch']) && !empty($_GET['batch'])) {
$batch = $_GET['batch'];
$sqlSelect = "SELECT * FROM policy where batch = '".$batch."' group by type order by policyprogress_id asc";
if (isset($_GET['type']) && !empty($_GET['type'])) {
$type = $_GET['type'];
$sqlSelect = "SELECT * FROM policy where batch = '".$batch."' and type = '".$type."' order by policyprogress_id asc";
}
}
Upvotes: 0
Views: 81
Reputation: 35900
You have a total of 3 queries
-- 1
SELECT * FROM policy order by policyprogress_id asc ;
-- 2
SELECT * FROM policy where batch = '".$batch."'
group by type order by policyprogress_id asc;
-- 3
SELECT * FROM policy where batch = '".$batch."' and type = '".$type."'
order by policyprogress_id asc;
Your second query will throw an error as You are doing SELECT *
but also using GROUP BY TYPE
.
In GROUP BY
queries, SELECT
clause can only include the grouped columns and aggregate functions. If you try to use other than grouped columns in the SELECT
clause then Oracle will throw ORA-00979: not a GROUP BY expression
error.
Upvotes: 1