dongliang1893 2018-09-09 03: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 03: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部