I have two tables with very similar structures.
Universidades
nombre | contenido | becas | fotos etc etc etc
Internados
nombre | todo | becas | fotos etc etc etc
I want to write an SQL statement that will select the nombre
from both of them and return it as an array only when it matches. From what I have seen UNION SELECT
seems to be the way to do this. I added WHERE
on the end and I think this is where its going wrong. So far I am receiving the first row of the first table.
What am I typing wrong?
$db = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
$data = $db->prepare("SELECT nombre FROM internados UNION SELECT nombre FROM universidades WHERE nombre = ?");
$data->execute(array($nombre));
apologies, I want to retrive one result from these two tables. Namees in the nombre
column are all individual and different in both tables