+ 2
How to search email id and password from different table of a single database with one query on click on login button.
To search the given id and password in different table if record doesn't match in first table then it search in second table of the same database.
10 odpowiedzi
+ 8
Notice the matching row from the 2nd table is duplicated for each row in the 1st table.
This obviously isn't the desired result.
----
An alternative option would be to use the UNION ALL operator between separate SELECT statements, one for each table.
See this example below:
SELECT email, password
FROM FIRST_TABLE
WHERE email = @email
UNION ALL
SELECT email, password
FROM SECOND_TABLE
WHERE email = @email;
If preferred, you could add the password criteria as well.
This will result with:
email3B | pass3B
You can review these results from the sample queries in the link below:
https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=14d6fb36ca8da8dc841d7173e500b67e
+ 8
🤦♂️🤷♂️?
+ 8
You can contact me here in this thread. 😉
I don't respond to technical questions in DM. Otherwise, I would be answering many questions all day without end. It's too much pressure to try to keep up with those DMs.
+ 6
Vikash Kumar I completely lost track of this question.
If you still need help, you'll need to provide more feedback than:
"Not working guys..."
and
"Any other method"
Otherwise, you might receive responses like what I last posted:
"🤦♂️🤷♂️?"
+ 4
rv7 I don't think using the ANSI SQL-89 implicit join syntax is the proper solution.
First, an error will result, in its current format, indicating the columns in the WHERE clause are ambiguous.
This should fix the syntax issue:
SELECT *
FROM FIRST_TABLE F,
SECOND_TABLE S
WHERE F.email = @email
OR S.email = @email;
However, even when the ambigous columns issue is resolved, the results will still NOT be what is expected. Rather, the results will combine each row from the FIRST_TABLE with each matching row from the SECOND_TABLE.
Let's say you're searching for 'email3B' which exists in the 2nd table. Now, let's say the FIRST_TABLE has 3 total records, none of which match the search criteria.
Well, then, the results might look as follows:
1 email1A | pass1A | email3B | pass3B
2 email2A | pass2A | email3B | pass3B
3 email3A | pass3A | email3B | pass3B
(continue...)
+ 2
Not working guys...
+ 2
Any other method
+ 1
This is kind of what joins are for, no? 😉
You've been provided with a few working examples above. If they aren't working for you, your syntax is likely incorrect or you're missing a semicolon at the end or maybe you're taking the examples literally and not substituting your own table names etc.
Either way those examples should work.
0
User a Union:
Select 1 as rowid, Email,Password
From table1
Where condition
Union
Select 2 as rowid, Email,Password from table2
Where condition
By exaining the rowid you know the Tablet that holds the information. If the Statement Returns No result the Login must fail
0
Can i contact you David Carroll