SQL - Check if data exists on either table

前端 未结 2 1541
不思量自难忘°
不思量自难忘° 2021-01-24 14:47

I have two tables in my database regarding the login details for both of my users (Librarians and Students) I have separated the user\'s details into 2 separate tables tblUserLi

2条回答
  •  深忆病人
    2021-01-24 15:43

    select StudentID,Password,FirstName,LastName from tblUserStudent where studentID='S1202836'
    union
    select LibrarianID,Password,null,null from tblUserLibrarian where LibrarianID='L1202836'
    

    I'm not sure if i understand your requirement correctly, but it seems you want a union, not a join, and since your librarian table has fewer columns than your user student table, you have to fill up with null columns so the column count matches.

提交回复
热议问题