Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group_by not working? #89

Open
jacobruvalcaba opened this issue Apr 7, 2015 · 1 comment
Open

group_by not working? #89

jacobruvalcaba opened this issue Apr 7, 2015 · 1 comment

Comments

@jacobruvalcaba
Copy link

I have a query that selects 4 columns from different tables, I also need to group them
but when whenever i try to group them I get an error on my page
This is the structure of my query

$this->datatables->select(first,second,third,MAX(CASE WHEN id = fid THEN 'T' ELSE 'F' end) as fourth');
->from(tableA);
$this->datatables ->join(......)
-->join(.....)
$this ->datatables->where(tableA.somevalue > 0);
$this->datatables->group_by(first,id,second,third);

I get this following message from my page ( I am using codeigniter for php)
Error Number: 42000

[Microsoft][SQL Server Native Client 10.0][SQL Server]Column 'tableA.BranchId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
select * from tableA join ..... group by first,id,second,third

As you can notice the error is clearly doing a 'select * from tableA' I don't know why is it doing that

@wiseguysby
Copy link

wiseguysby commented Jul 12, 2021

I have solution, but I don't know how to patch to git. pls follow this instruction

  1. create private variable after line private $order_by, example : private $query
  2. inside private function get_total_results, after if(strlen($this->distinct) > 0)
    {
    $this->ci->db->distinct($this->distinct);
    $this->ci->db->select($this->columns);
    }, add this line else this $this->ci->db->select($this->query);

yeahhhh....error is gone 👯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants