duanning9110 2015-07-31 10:08
浏览 124
已采纳

在查询中使用两个嵌套的select

I am using phpmyadmin 127.0.0.1.

The following code shows error but I cannot find anything wrong

$sde=" select * from 
(select * from students1
WHERE 
((PartCode = '$s1' OR PartCode =CONCAT('D', '$s1')) AND     (ElectiveSubject1='$s11' OR ElectiveSubject2='$s11' OR ElectiveSubject3='$s11')) 
ORDER BY PartCode, AdmitCode, RollCode 
LIMIT ${'rr'.$rnn.'1b'}, ${'rr'.$rnn.'1'})  
LIMIT $qa1, $qa2
";

$rde2=mysql_query($sde);

Please help me in finding the error. The error removes if we omit the portions outside the brakets ().

  • 写回答

1条回答 默认 最新

  • draj840143 2015-07-31 11:10
    关注

    The specific problem is that you are missing the table alias on the subquery. I think it would be easier to write the second condition using in:

    select s.* 
    from (select s.*
          from students1 s
          where ((PartCode = '$s1' OR PartCode = CONCAT('D', '$s1')) AND  
                 '$s11' in (ElectiveSubject1, ElectiveSubject2, ElectiveSubject3)
          order by PartCode, AdmitCode, RollCode 
          limit ${'rr'.$rnn.'1b'}, ${'rr'.$rnn.'1'}
         ) s
    LIMIT $qa1, $qa2;
    

    Next. You need to move off the "mysql_" interface. This is no longer supported. When you switch to "mysqli_", then you can parameterize the column values. This is a better approach.

    Next. You have three columns which only seem to differ by an integer at the end of their name. That is a sign of poor database design. In general, this means that your data model should have a junction table, with one row per student and elective subject.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置