2
In one system, I have 03 types of internal search:
And I would like to search in 03 unrelated tables:
Tabela1, table2 and Tabela3
For that, I tried the commands below:
SELECT * FROM `tabela1` WHERE NomeUsuarios LIKE 'Davi%' UNION SELECT * FROM `tabela2` WHERE NomeUsuarios LIKE 'Davi%' UNION SELECT * FROM `tabela3` WHERE NomeUsuarios LIKE 'Davi%'
The top one, made the mistake below:
1222 - The SELECT commands used have different number of columns
I tried that search and I couldn’t either:
SELECT * FROM `tabela1`, `tabela2`, `tabela3` WHERE tabela1.NomeUsuarios LIKE 'Davi%' OR tabela2.NomeUsuarios LIKE 'Davi%' OR tabela3.NomeUsuarios LIKE 'Davi%'
He returns to me all the names, regardless of whether they are David or not. How can I do this search?
Guys, I’m actually using Like. In the post I put manually and I ended up putting wrong, but I adjusted my post. I think it’s some problem in the configuration of mysql local or something. I’ll try it remotely to see if it works.
– user24136
About the problem of error #1222, fixed as follows, I changed the query to:
SELECT tabela1.NomeUsuarios FROM tabela1 WHERE tabela1.NomeUsuarios LIKE 'Davi%' UNION SELECT tabela2.NomeUsuarios FROM tabela2 WHERE tabela2.NomeUsuarios LIKE 'Davi%' UNION SELECT tabela3.NomeUsuarios FROM tabela3 WHERE tabela3.NomeUsuarios LIKE 'Davi%'
, but even having the name David in the 03 tables, he only returned me 1. In fact I need to bring the 03 results of the 03 tables.– user24136
@Fox.11 take a look at my issue.
– Andrei Coelho
Thanks Andrei. It worked!
– user24136
@Fox.11 quiet! Hug!
– Andrei Coelho