LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1037|回复: 2

mysql 是不是两个表都有的字段,在select一定得告之select从那个中选吗?

[复制链接]
发表于 2005-9-1 15:19:41 | 显示全部楼层 |阅读模式
mysql> select * from tmp ;
+---------+-------+
| article | price |
+---------+-------+
|    0001 |  3.99 |
|    0002 | 10.99 |
|    0003 |  1.69 |
|    0004 | 19.95 |
+---------+-------+

mysql> select * from shop ;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
|    0001 | A      |  3.45 |
|    0001 | B      |  3.99 |
|    0002 | A      | 10.99 |
|    0003 | B      |  1.45 |
|    0003 | C      |  1.69 |
|    0003 | D      |  1.25 |
|    0004 | D      | 19.95 |
+---------+--------+-------+

mysql> select article,dealer,price from shop,tmp where shop.article=tmp.article and shop.price=tmp.price ;
ERROR 1052: Column: 'article' in field list is ambiguous

why?

mysql> select shop.article,dealer,shop.price from shop,tmp where shop.article=tmp.article and shop.price=tmp.price ;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
|    0001 | B      |  3.99 |
|    0002 | A      | 10.99 |
|    0003 | C      |  1.69 |
|    0004 | D      | 19.95 |
+---------+--------+-------+
mysql> select tmp.article,dealer,shop.price from shop,tmp where shop.article=tmp.article and shop.price=tmp.price ;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
|    0001 | B      |  3.99 |
|    0002 | A      | 10.99 |
|    0003 | C      |  1.69 |
|    0004 | D      | 19.95 |
+---------+--------+-------+

按我自己的理解,article表不管select从哪个表中选择根据where都是唯一的结果
为什么还要我指定是哪个表的呢?

是不是两个表都有的字段,在select一定得告之select从那个中选吗?
 楼主| 发表于 2005-9-1 15:23:30 | 显示全部楼层
请问

lock 一个表的作用
回复 支持 反对

使用道具 举报

发表于 2005-9-2 15:09:45 | 显示全部楼层
第一问请看文档,第二问lock的作用就是在处理并发请求时为避免脏读或脏写(你在写入或修改时别人读取或修改或写入你正在处理的数据)将记录或数据表锁定
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表