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
SQL Server throws invalid column error on select list #460
Comments
Unfortunately I have no access to SQL Server, so I can't debug this. I suspect this is happening because SQL Server doesn't like having a Could you try running this same query but with a grouping function on the subselect? |
It took me a while but I hacked my way through the issue last night. In reference to http://dev.mysql.com/doc/refman/5.0/en/group-by-extensions.html I figured SQL server was more strict with the formatting of the GROUP BY clause and ended up appending each of the columns to the GROUP BY which ends up working. |
Can you show how you solved it? I'm having the same problem.. |
First make a BaseModel.php ..so i can get all columns names from all tables. <?php
// New File
class BaseModel extends \Eloquent {
public static function getTableName()
{
return with(new static)->getTable();
}
public function getColumnsNames() {
$table = with(new static)->getTable();
$connection = DB::connection();
$connection->getSchemaBuilder();
//$s = DB::getSchmema();
$grammar = $connection->getSchemaGrammar();
$table = $connection->getTablePrefix().$table;
$results = $connection->select($grammar->compileColumnExists($table));
return array_unique($connection->getPostProcessor()->processColumnListing($results));
}
} Second All models have to extend from BaseModel... instead of \Eloquent //grab the model instance
$model = $this->config->getDataModel();
$cols = $model->getColumnsNames(); // ------> New Line around Line 110
// ----> at line 119/120 instead of $query = $model->groupBy($table . '.' . $keyName);
foreach ($cols as $col) {
$model = $model->groupBy($table.'.'.$col);
}
$query = $model; And then some Pages work an other ar saying |
@janhartigan @edgji I've experienced the same issue and initially used the workaround of adding each column to the If the following generated SQL statement is being used to count the number of rows in the table, why is a
Is another possible solution to just remove the
Thanks. |
@ricksuggs: thanks!! That worked for me. |
In Laravel 4.1 I managed to set up administrator with a model for a table I replicated from SQL Server into MySQL for basic testing and setup. I got to the point where I needed to have this running on the existing SQL server data so I tried to connecting but I'm getting the following error
Column 'COLUMN' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. (SQL: SELECT COUNT(id) AS aggregate FROM (select [TABLENAME].* from [TABLENAME] group by [TABLENAME].[id]) AS agg) (Bindings: array ( ))
*(COLUMN and TABLENAME replace their respective actual property names)
The text was updated successfully, but these errors were encountered: