Check other mysql records

-2

I have the following data in a pivot table,

estado| tipo
libre | moto
libre | camioneta
libre | furgón
en uso| moto
libre | bicicleta
en uso| camioneta

So far I have only the basic query, I've tried anyway but I can not find the result, I'm using Laravel 5.4, but while I'm doing tests with phpmyadmin

SELECT * FROM 'cometido_vehiculo' WHERE estado = 0

and I need to get the types that are free is to say "Van and bicycle" When I do the query, I get the following result: "motorcycle, van, van, bicycle" any ideas? Edit the previous question because I did not know how to explain it well, greetings

    
asked by Renato 04.09.2017 в 21:57
source

1 answer

1

You need a subquery, use:

SELECT * FROM 'cometido_vehiculo' where tipo not in (SELECT distinct tipo from 'cometido_vehiculo' WHERE estado = 'en uso')

Depending on your example query, you may have to replace state = 'in use' with state = 1
I hope it helps you. Good luck

    
answered by 05.09.2017 / 18:01
source