Consultation with combined criteria

Asked

Viewed 38 times

1

I’m trying to assign more than one search criteria in the database and I can’t find anything that can help me. I’ll explain it better:

I have a database with a "city" field, where I want the daos assigned to that city to be returned. However, I wish another nearby city to be included as well, but I would not like to do this with an auxiliary table.

I’ve seen this being used with commas in the forms, but I have no idea how to do this in the query.

$acha = mysqli_query("
SELECT *
FROM pe_basedecisao 
WHERE cidade = 351015, 351013");
  • You can use a OR on condition as I understand SELECT * FROM pe_basedecisao WHERE cidade = 351015 OR cidade = 351013

  • SELECT * FROM pe_basedecisao WHERE cidade IN ("351015", "351013");

  • Thank you guys!

1 answer

4


You can do this with IN in mysql:

Query using 'IN'

SELECT * FROM pe_basedecisao WHERE cidade IN ("351015", "351013");

Translation of this query without 'IN'

SELECT * FROM pe_basedecisao WHERE cidade = "351015" OR cidade = "351013";

Reference : Mysql IN

Browser other questions tagged

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