0
I want to search in 2 tables of the database where the name equals the variable $nome
.
I would not like to join data as if they were FK, but pull all the information from these tables (other columns).
administradores
adm_id | nome | data_nasc | cod_user |
1 | rafael | 00/00/0000 | 63453 |
2 | paulo | 05/06/2005 | 34241 |
usuarios
user_id | nome | sobrenome | cod_user |
1 | rogério | silva | 32412 |
2 | silvio | lira | 21321 |
I tried to make a select
thus:
SELECT * FROM administradores.nome, usuarios.nome WHERE nome = '$nome';
And what is the expected result?
– Woss
Search tables for the name
– Teresa Santos
to bring data from two tables you need to make a
join
. What do you expect to receive with this select? Bring the name of the two tables?– Jorge.M
Could you give examples based on the data you put in the tables? If I looked for "paul", what would be the result? And if "paul" was in both tables?
– Woss
select * from tabela1 where campo = campo UNION select tabela2 where campo = campo
– Pedro Augusto
@Teresasantos, in this case, you can use one
join
or theunion
as quoted in some responses .– Jorge.M
That sounds like a XY problem and just with the details presented in the question there is no way to say whether it makes sense or not to do what you’re doing. If they are unrelated tables, I see no reason to create the relationship in the query.
– Woss
I just want to create a search system where I can search in a single input names that are in 2 separate tables
– Teresa Santos
Then improve your question by adding concrete examples. Place the complete structures of the two tables, some sample data and the expected results for some hypothetical queries. Without this, there is no way to verify the validity of the solution and any response will be based on speculation.
– Woss