+ 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.

8th Jun 2019, 4:12 AM
Vikash Kumar
Vikash Kumar - avatar
10 Answers
+ 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
8th Jun 2019, 6:38 AM
David Carroll
David Carroll - avatar
+ 8
šŸ¤¦ā€ā™‚ļøšŸ¤·ā€ā™‚ļø?
9th Jun 2019, 6:35 AM
David Carroll
David Carroll - avatar
+ 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.
13th Jul 2019, 4:48 AM
David Carroll
David Carroll - avatar
+ 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: "šŸ¤¦ā€ā™‚ļøšŸ¤·ā€ā™‚ļø?"
12th Jul 2019, 9:39 PM
David Carroll
David Carroll - avatar
+ 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...)
8th Jun 2019, 6:22 AM
David Carroll
David Carroll - avatar
+ 2
Not working guys...
8th Jun 2019, 11:28 PM
Vikash Kumar
Vikash Kumar - avatar
+ 2
Any other method
8th Jun 2019, 11:28 PM
Vikash Kumar
Vikash Kumar - avatar
+ 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.
14th Jul 2019, 5:13 PM
Mike
Mike - avatar
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
12th Jul 2019, 9:01 PM
Robert Niemann
0
Can i contact you David Carroll
13th Jul 2019, 4:33 AM
Vikash Kumar
Vikash Kumar - avatar