今天看织梦源代码的时候看到一句sql语句是这样的,
select '#@__archives' as maintable ,addtable from `#@__channeltype` where id=$id
我不明白这个语句是什么意思,#@__arcchives是一个表的名字, 而且被搜索的表#@__channeltype里没有这个名字的字段,不过倒是有maintable这个字段,那个这样搜索的意思是什么?具体语法呢?
高手指点,
select '#@__archives' as maintable ,addtable from `#@__channeltype` where id=$id
我不明白这个语句是什么意思,#@__arcchives是一个表的名字, 而且被搜索的表#@__channeltype里没有这个名字的字段,不过倒是有maintable这个字段,那个这样搜索的意思是什么?具体语法呢?
高手指点,
一般的查询语句不是这样的吗
select 字段1,字段2 from 表名 where 条件 而我看到的查询语句也是这样,
select 'dede_archives' as maintable ,addtable from `dede_channeltype` where id=1;
看起来是没什么特别的,
但是实际上在dede_channeltype这个表中呢没有dede_archives这个字段,倒是有maintable这个字段,在数据库里,dede_archives是另一个表的名字,这样会得出什么样的结果呢?
我试了一下,可以运行,达到一条数据,两个字段,maintable,addtable,值分别为dede_channeltype表中maintable,addtable字段的值,何解?
表示用值dede_archives作为字段maintable 的值,也即固定值
假如一个表中没有name字段,你也可以这样查询:
select "csdn" as name,age from people;
'dede_archives' as maintable:常量做为maintable字段的值,
+------+-------+
| id | total |
+------+-------+
| 1 | 80 |
| 2 | 90 |
+------+-------+
2 rows in set (0.03 sec)mysql> select 'test' as field_add,id,total from t1;
+-----------+------+-------+
| field_add | id | total |
+-----------+------+-------+
| test | 1 | 80 |
| test | 2 | 90 |
+-----------+------+-------+
2 rows in set (0.00 sec)mysql>
所以 select 1 as nn ... select 'CCC' as name 这些都是可以的。