Precious Pari Precious Pari - 9 days ago 5
MySQL Question

database query for single login form extracting data from two signup tables

There are two signup tables one for hire and one for work pictures of the both tables are given below:

Table 1:
table 1

Table 2
table 2

but i want to create single login form for both hire and work user
now i wrote this query for extracting data from both tables,

$sql = " SELECT *
FROM signup_hire
LEFT OUTER JOIN signup_work ON signup_hire.id = signup_work.id

UNION

SELECT *
FROM signup_hire
RIGHT OUTER JOIN signup_work ON signup_hire.id = signup_work.id
WHERE signup_hire.email = '$myusername' and signup_hire.password = '$mypassword'
OR signup_work.email = '$myusername' and signup_work.password = '$mypassword'";


but I am receiving 'invalid email or password' - what is the correct query to use?

Answer

Have you tried a simple UNION? Query the first table and add a UNION with the same result on the second table, this will will return the results if it matches one of the tables, keep in mind that column names will the ones on the first table regardless which one matches. Also, be sure both tables have the same number of columns or list the fields you need instead of *

SELECT id,name,email
FROM signup_hire
WHERE signup_hire.email = '$myusername'
  AND signup_hire.password = '$mypassword'
UNION
SELECT id,name,email
FROM signup_work
WHERE signup_work.email = '$myusername'
  AND signup_work.password = '$mypassword';
Comments