I am tryng to make a join in laravel 5.1
here is my code
Venta::where('dbo.Venta.mov', 'some' )
->where('dbo.Venta.Estatus', 'C')
->join('dbo.Cte', 'dbo.Cte.Client', '=', 'dbo.Venta.Cliente')
->where('dbo.Venta.Suc', '=','1')
->paginate(10);
but i have the error:
SQLSTATE [42000]: [Microsoft] [ODBC Driver for SQL Server 11] [SQL Server] The 'Client' column has been specified multiple times for 'temp_table'.
Can somebody please help me solve this issue?
Related
I was trying to run this query in laravel:
$siswa = DB::table('siswa')
->join('pengambilankelas', 'siswa.id_siswa', '=', 'pengambilankelas.id_siswa')
->join('subcpmkpengambilan', 'pengambilankelas.id_pengambilanKelas', '=', 'subcpmkpengambilan.id_pengambilanKelas')
->join('tesformatif', 'subcpmkpengambilan.id_subcpmkpengambilan', '=', 'tesformatif.id_subcpmkpengambilan')
->select('siswa.*', 'tesformatif.*', DB::raw('max(tesformatif.nilai_tesFormatif) as max_nilai'))
->groupBy('siswa.id_siswa')
->where('pengambilankelas.id_kelas','=', $id_kelas)
->where('subcpmkpengambilan.id_subCPMK', '=', $currentSubcpmk->id_subCpmk)
->where('subcpmkpengambilan.status_subcpmkpengambilan', '=', 3)
->get();
then i got this error:
SQLSTATE[42000]: Syntax error or access violation: 1055 'dil.siswa.identitas_siswa' isn't in GROUP BY (SQL: select `siswa`.*, `tesformatif`.*, max(tesformatif.nilai_tesFormatif) as max_nilai from `siswa` inner join `pengambilankelas` on `siswa`.`id_siswa` = `pengambilankelas`.`id_siswa` inner join `subcpmkpengambilan` on `pengambilankelas`.`id_pengambilanKelas` = `subcpmkpengambilan`.`id_pengambilanKelas` inner join `tesformatif` on `subcpmkpengambilan`.`id_subcpmkpengambilan` = `tesformatif`.`id_subcpmkpengambilan` where `pengambilankelas`.`id_kelas` = 5 and `subcpmkpengambilan`.`id_subCPMK` = 6 and `subcpmkpengambilan`.`status_subcpmkpengambilan` = 3 group by `siswa`.`id_siswa`)
Query run fine outside laravel. this post tell me to disable strict mode
and it works.
is there a better way without disabling strict mode? is it even save to do so?
ps. I'm sorry the database is in indonesian.
You may have the sql_mode ONLY_FULL_GROUP_BY enabled. To disable it run in the mysql console the following command:
mysql > SET GLOBAL sql_mode=(SELECT REPLACE(##sql_mode,'ONLY_FULL_GROUP_BY',''));
References
Disable ONLY_FULL_GROUP_BY
I'm Running the following query without any problem in MySQL (5.7.21) Database but this query throws error on my hosting server database which is MariaDB (10.1.47-MariaDB) and I don't have super permission to change the sql mode.
$projects = V2Project::leftJoin('v2_project_locations as v2pl', 'v2pl.project_id', 'v2_projects.id')
->leftJoin('v2_locations as v2l', 'v2l.id', 'v2pl.location_id')
->selectRaw('v2_projects.id, v2_projects.name, group_concat(v2l.name) as locations')
->withDepartmentInMind()
->onlyAuthorizedObjects();
if($by_current_step == true) {
$projects = $projects->where('current_step', 'plan');
}
if($search_val) {
$projects = $projects->whereIn('v2_projects.id', $search_val);
}
$projects = $projects->groupBy('v2_projects.id')->paginate(10);
$projects->appends(Input::except('page', '_token'));
Error:
SQLSTATE[42000]: Syntax error or access violation: 1055 'pm_form_moe.v2_projects.name' isn't in GROUP BY (SQL: select v2_projects.id, v2_projects.name from `v2_projects` group by `v2_projects`.`id`)
I also tried to add every column, but I need the functionality the same as mySQL without adding all columns.
Read about ONLY_FULL_GROUP_BY, then decide what to remove from your SELECT or what to add to the GROUP BY. Don't worry about setting the flag; your code is bad and needs to be fixed. And it was bad in the older version when it did not complain.
(If you show us the generated SQL, we can discuss it further.)
I'm getting up a new server laravel framework, correct the MySQL query to get the data.
Running Laravel 5.6.28, MySql 5.7.21, PHP 7.2.
$query = DB::table('Student a')->select([DB::raw('SQL_CALC_FOUND_ROWS')], 'a.*', b.*')->leftjoin('girls b', 'a.id', '=', 'b.id')->where('a.name', '!=', 'null');
$query->skip($iPagNo)->take($iSwRws);
$sqlPg = $query->get();
print_r($sqlPg);
I dont want to believe there is a bug in laravel 5.5 cos i am amazed how i keep getting errors on the Eloquent Query Builder when ever i use the groupBy in my query.
Tried converting this SQL that works seamlessly to Eloquent and i keep getting Errors on the groupBy..
Had a similar issue with an SQL which i complained here and till now i have not gotten a perfect answer for it
open issue here
SELECT * FROM arm_articles
INNER JOIN arm_interest ON arm_articles.article_category = arm_interest.category_id
WHERE arm_articles.article_contributor_id='1322'
GROUP BY arm_articles.article_id
ELOQUENT VERSION THAT RETURNS ERROR
$contributor_id =1322;
DB::table('arm_articles')
->join('arm_interest', function($join) {
$join->on('arm_articles.article_category','=','arm_interest.category_id');
})
->having('arm_articles.article_contributor_id', '=', $contributor_id)
->groupBy('arm_articles.article_id')->get()
ERROR MESSAGE
SQLSTATE[42000]: Syntax error or access violation: 1055 'knowledge_db.arm_articles.id' isn't in GROUP BY (SQL: select * from 'arm_articles' inner join 'arm_interest' on 'arm_articles'.'article_category' = 'arm_interest'.'category_id' group by 'arm_articles'.'article_id' having 'arm_articles'.'article_contributor_id' = 1322)
So like i said b4 its really weared why i will get the error in the first place as adding ->toSql to the query returns the right SQL.
Add this configuration to your mysql database config in config/database.php:
'mysql' => [
....
'strict' => false,
//'strict' => true,
],
Edit sql_mode in your mysql config file (my.ini or my.cnf)
[mysqld]
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Restart your MySQL
I am trying to set pagination in Laravel 5.1, here is what I am trying to do:
$bridal_requests_data = \DB::table('bridal_requests')->leftJoin('audiences', function($join) {
$join->on('bridal_requests.id', '=', 'audiences.request_id');
})
->orderBy('bridal_requests.id', 'DESC')->paginate('15', array('bridal_requests.*'));
it is giving the following error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) as aggregate from bridal_requests left join audiences on bridal_requests' at line 1 (SQL: select count(bridal_requests.*) as aggregate frombridal_requestsleft joinaudiencesonbridal_requests.id=audiences.request_id`)
As stated above, it is not working for bridal_requests.*, but if I use brial_requests.id then it works, but I need to use get all data from bridal_requests table.
You should use:
$bridal_requests_data = \DB::table('bridal_requests')->select('bridal_requests.*')->leftJoin('audiences', function($join) {
$join->on('bridal_requests.id', '=', 'audiences.request_id');
})
->orderBy('bridal_requests.id', 'DESC')->paginate(15);