How To Use Where IN in Query

Asked

Viewed 52 times

0

How can I perform a query below with mysql in the:

SELECT
    gps.positions.id,
    gps.positions.protocol,
    gps.positions.deviceid,
    gps.positions.servertime,
    gps.positions.devicetime,
    gps.positions.fixtime,
    gps.positions.valid,
    gps.positions.latitude,
    gps.positions.longitude,
    gps.positions.altitude,
    gps.positions.speed,
    gps.positions.course,
    gps.positions.address,
    gps.positions.attributes,
    gps.positions.accuracy,
    gps.positions.network,
    sing.veiculos.identificacao,
    sing.veiculos.id_tipo,
    sing.veiculos.descricao,
    sing.veiculos.deviceid
FROM gps.positions
LEFT JOIN sing.veiculos ON sing.veiculos.deviceid = gps.positions.id
WHERE gps.positions.devicetime IN ((SELECT MAX(devicetime) FROM positions GROUP BY deviceid));

Thanks in advance and I’m waiting for a light.

  • You can use the Facade DB and use the static method raw() to make an instruction SQL, for example DB::raw('SELECT ...') . Any doubt is always good to read the documentation: https://laravel.com/docs/5.6/queries

1 answer

0

There’s another apparently simpler way to do what you want:

$dados = DB::table('tabela')->whereIn('id', [1, 2, 3])->get();

For more information: https://laravel.com/docs/5.7/queries

Browser other questions tagged

You are not signed in. Login or sign up in order to post.