今天看织梦源代码的时候看到一句sql语句是这样的, 
select '#@__archives' as maintable ,addtable from `#@__channeltype` where id=$id 
我不明白这个语句是什么意思,#@__arcchives是一个表的名字, 而且被搜索的表#@__channeltype里没有这个名字的字段,不过倒是有maintable这个字段,那个这样搜索的意思是什么?具体语法呢? 
高手指点,

解决方案 »

  1.   

    #@__archives中的#@会被替换成表前缀~~检查一下你的PHP手册。
      

  2.   

    不好意思,可能我没表达清楚,
    一般的查询语句不是这样的吗
    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字段的值,何解?
      

  3.   

    select 'dede_archives' as maintable ,addtable from `dede_channeltype` where id=1; --------------
    表示用值dede_archives作为字段maintable 的值,也即固定值
      

  4.   

    '#@__archives'应该是一个常量。
    假如一个表中没有name字段,你也可以这样查询:
    select "csdn" as name,age from people;
      

  5.   

    maintable中的值应该是dede_archives,
    'dede_archives' as maintable:常量做为maintable字段的值,
      

  6.   

    示例:mysql> select * from t1;
    +------+-------+
    | 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>
      

  7.   

    select xxx from tableName where yyyy=zzz;select 后这个 xxxx 可以是 1) 字段,2) 表达式
    所以 select 1 as nn ...   select 'CCC' as name 这些都是可以的。
      

  8.   

    ok,这样说我就懂了,谢谢大家,特别是vinsonshen,谢谢你举的例子,我懂了,