AP aul AP aul - 12 days ago 6
PHP Question

How to search into two table where they have different column

is there any way I can search the data of a table where I will use a two criteria Firstname and lastname?

Table 1

Firstname | LastName | Gender

| Donald | Trump | Male|


Table 2

GFirstName | GLastName | Gender

|Hillary| Clinton | Female

|Donald | McDonald| Female


in my case I would like to Search for "Donald Trump"

and MySQL data should show me info of

table 1

Donald | Trump| Male


I tried using this query but it gives me nothing

SELECT *
FROM table1
WHERE 'Firstname' LIKE %Donald Trump%
OR 'LastName' LIKE %Donald Trump%
UNION ALL
SELECT *
FROM table2 WHERE 'Firstname' LIKE %Donald Trump%
OR 'LastName' LIKE %Donald Trump%

Answer

try

SELECT *
  FROM table1
  WHERE 
         CONCAT (Firstname, ' ',LastName)  LIKE '%Donald Trump%' 
  UNION ALL
  SELECT *
  FROM table2 WHERE CONCAT (Firstname, ' ',LastName)  LIKE '%Donald Trump%'
Comments