Multiple SQL column query - Laravel

Asked

Viewed 42 times

-1

Guys, I’m trying to make a query, where I have several fields to perform this search, and some null field may come. I’m using Laravel with Angular, I don’t know if I can do this consultation on the front even, I wanted to leave this responsibility to the same angle. If I can’t, how can I make the query clauses, SQL itself or by Laravel query.

inserir a descrição da imagem aqui

I tried to make a simple query to test using AND or

inserir a descrição da imagem aqui

If I put a condition with OR, of course it will meet one of the conditions if it is true, it brings the result of the first condition

But I need that in this case, if the fields are not null, it can bring the result of the 2 conditions, then when I try to put AND, it brings the result

If you see a null field from the view, it does not show the result

inserir a descrição da imagem aqui

How can I make a query with all those fields in the view, knowing that some NULL field can come ?

  • In place of os.status = NULL utilize os.status IS NULL, after all NULL is an absence of values and therefore cannot be compared with the equal operator.

  • I left == NULL there as an example that NULL fields can come from the view, but in this way ect * from order_services as os Where os.Hierarchy = 'Common' and os.status = 'Provisional'; it shows output

  • Study the concept of NULL in more detail and why it is necessary to use it IS NULL / IS NOT NULL.

1 answer

0

I thought you had the same situation with the query of the Laravel, but, she answered me, I added several wheres and solved

ex: ->Where('table.campo1', $request->campo1) ->Where('table.campo2', $request->campo2) . . . .

Browser other questions tagged

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