I am doing a simple project where I take StudentID & DateOfBirth from the user and give them their exam result. Now I have two tables.
Table user having field
我正在做一个简单的项目,我从用户那里学习StudentID和DateOfBirth并给他们考试结果。现在我有两张桌子。表用户有字段
- UserID
- DateOfBirth
& result having rows
&结果有行
- UserID
- sub1Marks
- sub2Marks
- sub3Marks
Now, I need to ask the users their ID and Date of Birth and match it from both the columns and display the results.
现在,我需要询问用户他们的ID和出生日期,并从两列中匹配并显示结果。
Please help me out !
请帮帮我!
2 个解决方案
#1
0
Hi you need to do a table join.
嗨,你需要做一个表加入。
select table2.sub1Marks, table2.sub2marks, table2.sub3marks, table2.userId
from <tablename2> table2 inner join <tablename1> table1
on table2.userId = table1.userId
where table1.userID = <userid> and
table1.DateOfBirth = <DOB>
Though before posting your question try researching it for you. What you are doing is the bread and button of SQL and you really should try and learn it otherwise you will struggle with everything else.
虽然在发布您的问题之前,请尝试为您研究它。你正在做的是SQL的面包和按钮,你真的应该尝试学习它,否则你将与其他一切斗争。
#2
0
Use this SQL:
使用这个SQL:
SELECT r.sub1Marks, r.sub2Marks, r.sub3Marks
FROM results r
INNER JOIN user u
ON u.userID = r.UserID
AND u.UserID = [users ID]
AND u.DateOfBirth = [users Date of Birth]
Obviously replace [users ID]
and [users Date of Birth]
with the data the user submits.
显然,用用户提交的数据替换[用户ID]和[用户出生日期]。
#1
0
Hi you need to do a table join.
嗨,你需要做一个表加入。
select table2.sub1Marks, table2.sub2marks, table2.sub3marks, table2.userId
from <tablename2> table2 inner join <tablename1> table1
on table2.userId = table1.userId
where table1.userID = <userid> and
table1.DateOfBirth = <DOB>
Though before posting your question try researching it for you. What you are doing is the bread and button of SQL and you really should try and learn it otherwise you will struggle with everything else.
虽然在发布您的问题之前,请尝试为您研究它。你正在做的是SQL的面包和按钮,你真的应该尝试学习它,否则你将与其他一切斗争。
#2
0
Use this SQL:
使用这个SQL:
SELECT r.sub1Marks, r.sub2Marks, r.sub3Marks
FROM results r
INNER JOIN user u
ON u.userID = r.UserID
AND u.UserID = [users ID]
AND u.DateOfBirth = [users Date of Birth]
Obviously replace [users ID]
and [users Date of Birth]
with the data the user submits.
显然,用用户提交的数据替换[用户ID]和[用户出生日期]。