[英]how to use multiple select statement in a query
我发现很难在查询中加入多个select语句。 如果我选择一个查询,它可以正常工作,但是将带有UNIC命令的select语句连接起来什么也没显示。 我在做什么,这可能是错误的。
$sel=mysql_query ("SELECT *
FROM studentmark join
student
ON studentmark.student_id = student.username join
subject
ON subject.code = studentmark.code
where student.username='$name' AND studentmark.YEAR = '$ya' AND
studentmark.TERM = 'THIRD')
//it works fine without using the union for a single query but joining the query there is nothing display
UNION(SELECT TOTAL AS secondterm
FROM studentmark
JOIN subject ON subject.code=studentmark.code
WHERE studentmark.student_id='$name'
AND studentmark.YEAR='$ya'
AND studentmark.TERM = 'SECOND')UNION(SELECT TOTAL AS firstterm
FROM studentmark
JOIN subject ON subject.code=studentmark.code
WHERE studentmark.student_id='$name'
AND studentmark.YEAR='$ya'
AND studentmark.TERM = 'FIRST'");
$fetch=mysql_fetch_array($sel);
$count=mysql_num_rows($sel);
$sel=mysql_query ("SELECT YEAR, TERM, CODE, student_id, ContAss20, AsgClassWk10, Test2nd10,Exam60, Total,tname
FROM studentmark join
student
ON studentmark.student_id = student.username join
subject
ON subject.code = studentmark.code
where student.username='$name' AND studentmark.YEAR = '$ya' AND
studentmark.TERM = 'THIRD')
//it works fine without using the union for a single query but joining the query there is nothing display
UNION(SELECT null, null, null, null, null, null, null,null, Total as secondterm, null
FROM studentmark
JOIN subject ON subject.code=studentmark.code
WHERE studentmark.student_id='$name'
AND studentmark.YEAR='$ya'
AND studentmark.TERM = 'SECOND')UNION(SELECT TOTAL AS firstterm
FROM studentmark
JOIN subject ON subject.code=studentmark.code
WHERE studentmark.student_id='$name'
AND studentmark.YEAR='$ya'
AND studentmark.TERM = 'FIRST'");
$fetch=mysql_fetch_array($sel);
$count=mysql_num_rows($sel);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.