dongliang1893 2018-09-09 11:28
浏览 83
已采纳

有没有办法缩短这些查询?

I am just beginning, the following queries work but they seem to long and messy. How can I make these queries shorter?

Here is my code:

if ($result = $mysqli->query("select bestelling.datum,klant.klant_code,klant.adres,klant.naam,reis.bestemming,reis.klasse,reis.prijs_in_euro,reis.geannuleerd from klant,reis,bestelling where bestelling.bestelling_code = klant.klant_code and klant.klant_code = reis.reis_code"))


if ($stmt = $mysqli->prepare("UPDATE bestelling,klant,reis SET datum = ?, naam = ?, adres = ?, bestemming = ?, klasse = ?, prijs_in_euro = ?
        WHERE klant.klant_code=? and bestelling.bestelling_code = klant.klant_code and klant.klant_code = reis.reis_code"))


if($stmt = $mysqli->prepare("SELECT * FROM bestelling,klant,reis WHERE klant.klant_code=? and bestelling.bestelling_code = klant.klant_code and klant.klant_code = reis.reis_code"))
  • 写回答

2条回答 默认 最新

  • dongpan1308 2018-09-09 11:39
    关注

    shorter could be not but more clear yes .. you should not use ancient join based on implicit where condition you should use explicit inner join

    if ($result = $mysqli->query("
            select  bestelling.datum
                    ,klant.klant_code
                    ,klant.adres
                    ,klant.naam
                    ,reis.bestemming
                    ,reis.klasse
                    ,reis.prijs_in_euro
                    ,reis.geannuleerd 
            from klant 
            INNER JOIN reis ON  klant.klant_code = reis.reis_code
            INNER JOIN bestelling ON  bestelling.bestelling_code = klant.klant_code 
            "))
    

    and you could use alias of table name

    if ($result = $mysqli->query("
            select  b.datum
                    ,k.klant_code
                    ,k.adres
                    ,k.naam
                    ,r.bestemming
                    ,r.klasse
                    ,r.prijs_in_euro
                    ,r.geannuleerd 
            from klant k  
            INNER JOIN reis r ON  k.klant_code = r.reis_code
            INNER JOIN bestelling b  ON  b.bestelling_code = k.klant_code 
            "))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化