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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器