Value tuple using mysql Procedure

Asked

Viewed 599 times

1

I have a form where there are two fields, a service and another value, for each service the user has to put a value, after the user chooses, I check in the bank how many lines will return me with this filter. For the procedure I pass two parameters.

Example of the procedure call:
call('1,2,3', '100,200,300')

This is the call of the procedure, the procedure will receive these two fields being that each of these fields is like a array. I want to know how I can make one select where I search for example:

SELECT *
  FROM tabela 
 WHERE codigo = 1
   AND valor = 2
   AND codigo = 2
   AND valor = 20
   AND codigo = 3
   AND valor = 30

But not able to do this, because everything is like an array, someone has some idea?

  • 1

    Post the structure of your table.

  • 1

    From what I understood the first value refers to the first service, the second value to the second service up to the nth. So you are looking for a service 1 with the value 100? Service 2 with value 200? select * from Where (code = 1 and value=100) or (code = 2 and value = 200) or (code = 3 and value = 300) ?

1 answer

1

I don’t know if you’ll be able to make the query, but try using

WHERE codigo IN(1, 2, 3) and valor IN(2, 20, 30)

But the return would be any code and value you’re passing.

I believe you will have to use maybe a UNION, with as many Selects as necessary, in your example would be 3.

Browser other questions tagged

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