[英]Query in Laravel 5.7 and PostgreSQL
I have a problem to make a query in Laravel 我在Laravel中进行查询时遇到问题
My query in POSTGRESQL is: 我在POSTGRESQL中的查询是:
SELECT con.id, con.vehiculo_id, con.cre, ve.chofer_id, ve.placa
FROM conciliaciones as con
JOIN vehiculos as ve
on con.vehiculo_id = ve.id or con.vehiculo_id IS NULL or con.vehiculo_id IS NOT NULL;
The problem with the query is that the plate is repeated when there should only be 1 single row with the data plate the rest is null 该查询的问题是,当数据板仅应有1个单行时,该板将被重复
I have the following code, but it does not work: 我有以下代码,但不起作用:
$conciliacion = DB::table('conciliaciones')
->join('vehiculos','conciliaciones.vehiculo_id','=','vehiculos.id')
->select('conciliaciones.*','vehiculos.placa')
->whereNull('conciliaciones.vehiculo_id')
->whereNotNull('conciliaciones.vehiculo_id')
->get();
How can I make the query? 我该如何查询?
In the query, select other columns but is Similarly that I need in Laravel 在查询中,选择其他列,但在Laravel中需要类似
thanks 谢谢
my solution xD 我的解决方案xD
$conciliacion = DB::table('conciliaciones')
->leftJoin('vehiculos','vehiculos.id', '=', 'conciliaciones.vehiculo_id')
->select('conciliaciones.*','vehiculos.placa')
->orderBy('conciliaciones.id')
->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.