简体   繁体   English

与使用php的mysql嵌套选择查询混淆

[英]confusing with mysql Nested Select Query using php

please help to find what the mistake here. 请帮忙找出这里的错误。 Actually i am a beginner.. Help Me.. 其实我是初学者..帮帮我..

$query1="select Sub_Code,Sub_Name from subj_mast where Dept_id='(select Dep_Id from academic where Reg_No=$reg)' and Sem='$sem'";

The above query is not working but when i split like this its working... 上面的查询不起作用,但当我像这样分裂它的工作......

$query2="select Dep_Id from academic where Reg_No=$reg";
$query3="select Sub_Code,Sub_Name from subj_mast where Dept_id='104' and Sem='$sem'";

here 104 is Dept_id corresponds to Reg_No given. 这里104是Dept_id对应于给定的Reg_No。 104 is got by using query2. 使用query2获得104。 Confused a lot ... is my query1 is right??? 困惑了很多...是我的查询1是对的???

You're wrapping your subquery inside of quotes. 您将子查询包含在引号内。 Remove the quotes. 删除引号。

Eg: 例如:

$query1="select Sub_Code,Sub_Name from subj_mast where Dept_id=(select Dep_Id from academic where Reg_No=$reg) and Sem='$sem'";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM