0

Hi! How to use select query for 4tables with same column name like name, password and it goes to different page through usertype

22nd Jan 2022, 3:29 PM
Logan Nathan
11 Antworten
+ 1
Somebody here already hinted that the tables could be joined by the UNION clause. If you prefer to not use UNION in your query, then you could create a View in the database that joins them by UNION and otherwise looks and behaves like a single table for queries. The WITH statement shown in my prior post includes a good example of how you might construct the View query. You could take the mystery out of this if you would follow up by showing the SQL query that you tried. Add a *detailed* description of what happens and why it does not match your intended result. Without that information we are quickly heading toward an impasse.
23rd Jan 2022, 5:31 PM
Brian
Brian - avatar
+ 1
I am not sure that I understand your question. Maybe what you need is a UNION query. SELECT * FROM table1 WHERE Name='xxxx' AND usertype='yyy' UNION SELECT * FROM table2 WHERE Name='xxxx' AND usertype='yyy' UNION SELECT * FROM table3 WHERE Name='xxxx' AND usertype='yyy' UNION SELECT * FROM table4 WHERE Name='xxxx' AND usertype='yyy'
22nd Jan 2022, 6:00 PM
Brian
Brian - avatar
+ 1
Would you care to show your query? It might help in clarifying what you are attempting to do.
22nd Jan 2022, 6:17 PM
Brian
Brian - avatar
+ 1
Thanks for you answer but it does not work I tried lot of times.
22nd Jan 2022, 6:17 PM
Logan Nathan
+ 1
One database had 4 tables with same column name like name , password in each table how to query for this. To login
22nd Jan 2022, 6:22 PM
Logan Nathan
+ 1
I am still hoping to see your attempt. It would clear many questions. Also, which SQL engine are are working with? Maybe you are looking for a way to choose the table based on usertype? In SQL Server there is a CHOOSE() function that might be useful. I think you can do something like this: @usertype=4; -- 1 thru 4 SELECT name, password FROM CHOOSE(@usertype, table1, table2, table3, table4) EDIT: On second thought, this might not work. CHOOSE is not intended for table selection.
22nd Jan 2022, 7:34 PM
Brian
Brian - avatar
+ 1
Still throwing darts in the dark, here is another idea that is useful on SQL Server. WITH User AS ( SELECT 1 as UserType, name, pwd FROM table1 UNION SELECT 2 as UserType, name, pwd FROM table2 UNION SELECT 3 as UserType, name, pwd FROM table3 UNION SELECT 4 as UserType, name, pwd FROM table4 ) SELECT name, pwd FROM User WHERE UserType = 2
22nd Jan 2022, 8:03 PM
Brian
Brian - avatar
0
Logan Nathan is your question answered? If yes, please mark the best answer. If no, please explain further. Show what you tried. Describe what you expected. Explain why the output does not match what you wanted.
23rd Jan 2022, 4:53 PM
Brian
Brian - avatar
0
Is not worked yet
23rd Jan 2022, 4:56 PM
Logan Nathan
0
I have 4 tables like admin, student, faculty, superadmin details it has same column name like email, pwd. How can i connect these tables for single login form.
23rd Jan 2022, 5:01 PM
Logan Nathan
0
I will give answer of questions in fixed time
24th Jan 2022, 12:38 PM
Iman Singh Ruchal