dongtao1262
dongtao1262
2015-07-23 10:36

临时表创建

已采纳

I am debuging php website and don't know how mysql query in it works. The code is:

$query = "
        SELECT
            WR.*,           
            W.*,
            D.*         
        FROM
            {#table} WR
        LEFT JOIN words W
            ON WR.word_id = W.word_id
        LEFT JOIN words_descriptions WD
            ON W.word_id = WD.word_id
        LEFT JOIN descriptions D
            ON WD.description_id = D.description_id
        " . $user_words_sql . "
        WHERE 
            title_len > 3
            AND W.in_game = 1
            " . $frequency_sql . " 
            " . $type_sql . "   
        GROUP BY 
            WR.word_id, 
            WR.description_id               
        ORDER BY
            $additional_order W.frequency DESC      
    ";

My question is where table WR is created, is it temporary table created in this peace of code or is it created somewhere else? Also, what this expression {#table} does?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douya2007 douya2007 6年前

    The value "WR" is an alias for the query, not a temporary table. It doesn't copy the data in memory, it's just a shortcut to make the query shorter/easier to read. Here's an example:

    SELECT * FROM countries c WHERE c.code = "GB"
    

    Expands to be:

    SELECT * FROM countries WHERE countries.code = "GB"
    

    @machineaddict was correct, the {#table} has no significance in MySQL - it's likely that this is being replaced at a later stage by another part of your PHP application.

    点赞 评论 复制链接分享