1
I need to create an SQL query that may or may not have multiple arguments. Example:
Pesquisa 1: "João Goiânia"
Pesquisa 2: "Goiânia João"
Pesquisa 3: "João Advogado Goiânia"
The query must go through three fields: name, city, profession. Since the arguments can be in one, two or in all of them.
Imagining a populated table:
id, nome, cidade, profissão
1, Maria, Brasília, Advogado
2, José, Anápolis, Engenheiro
3, João Carlos, Goiânia, Advogado Trabalhista
4, João da Silva, Goiânia, Médico
The result for search 1 and 2 would be records 3 and 4, and for search 3 would be only record 3.
I thought I’d use campo IN (arg1, arg2, arg3)
, however there is the possibility that the argument is not complete, as in the example. What is the best solution?
My database is Postgresql 9.4
What is your database? Mysql, SQL Server, Firebird....
– Matheus Ribeiro
since you don’t know how many fields or the order, one option would be to create a *full text index'
– Ricardo Pontual
@Matheusribeiro Postgresql 9.4
– João Francisco
@Ricardopunctual I’m reading about your suggestion, and actually the textual search seems to me to be a good solution. As soon as you find a good and complete article on the subject put here.
– João Francisco
Siml to the
postgresql
I believe it is. Here’s a good read: full text– Ricardo Pontual