mysql语法解释 [英] mysql syntax explanation

查看:32
本文介绍了mysql语法解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 a.*、c.name、...a.access 等是什么意思.换句话说,当我在点之前添加一个字母和点的功能时,我到底指的是什么.

I would like to know what the a.*, c.name, ... a.access etc means. In other words, what exactly am I referring to when I add a letter before the dot and the funciton of the dot.

这是我发现这种情况的代码示例:

Here is an example of code where I found this occurrence:

$query = "SELECT a.*, c.name as categoryname,c.id as categoryid, ".
         "c.alias as categoryalias, c.params as categoryparams".
        " FROM #__k2_items as a".
        " LEFT JOIN #__k2_categories c ON c.id = a.catid";

        $query .= " WHERE a.published = 1"
        ." AND a.access <= {$aid}"
        ." AND a.trash = 0"
        ." AND c.published = 1"
        ." AND c.access <= {$aid}"
        ." AND c.trash = 0"
        ;

推荐答案

如果您查看 FROM 子句,您会看到:

If you look at the FROM clause, you see this:

FROM #__k2_items as a

LEFT JOIN 子句中,您会看到:

And in the LEFT JOIN clause, you see this:

LEFT JOIN #__k2_categories c ON c.id = a.catid

别名#__k2_items 表(无论它真正叫什么)到名称a#__k2_categoriesc,分别.在这种情况下,实际上只是为了节省输入并提高查询的可读性.

That aliases the #__k2_items table (whatever it's really called) to the name a, and #__k2_categories to c, respectively. In this case it's just to save typing and improve the readability of the query, really.

点将列名与表名相关联,以便 MySQL 知道要查找哪些表,以防查询涉及的多个表中有相同名称的列.也就是说,它解决了列歧义.

The dot associates a column name to a table name so MySQL knows which tables to look in, in case you have columns of the same name in more than one table involved in the query. That is, it resolves column ambiguity.

这篇关于mysql语法解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆