我要查询多个表里相同字段的相同内容:应该怎么写代码?这个是cms的引用,请高手指点一下。 {pc:get sql="select * from v9_news where relate = '$relate' union select * from v9_video where relate = '$relate' union select * from v9_picture where relate = '$relate' union select * from v9_index where relate = '$relate' union select * from v9_price where relate = '$relate' union select * from v9_moble where relate = '$relate'"}
{loop $data $rs}
<a href="{$rs['url']}" title="{$rs['title']}" target="_blank">{$rs['part']}</a>
{/loop}
{/pc}
只有前面三个表的时候是不会出错的,但是加到6个表的时候就出错,请高手指点一下,如何写这段代码才正确:select * from v9_news where relate = '$relate' union select * from v9_video where relate = '$relate' union select * from v9_picture where relate = '$relate' union select * from v9_index where relate = '$relate' union select * from v9_price where relate = '$relate' union select * from v9_moble where relate = '$relate'有简单的写法吗?
{loop $data $rs}
<a href="{$rs['url']}" title="{$rs['title']}" target="_blank">{$rs['part']}</a>
{/loop}
{/pc}
只有前面三个表的时候是不会出错的,但是加到6个表的时候就出错,请高手指点一下,如何写这段代码才正确:select * from v9_news where relate = '$relate' union select * from v9_video where relate = '$relate' union select * from v9_picture where relate = '$relate' union select * from v9_index where relate = '$relate' union select * from v9_price where relate = '$relate' union select * from v9_moble where relate = '$relate'有简单的写法吗?
解决方案 »
- 使用华众后无法创建MYSQL数据库,MS SQL可以
- 测试mysql.Access denied for user 'ODBC'@'localhost' (using password: NO) 怎样解决?
- mysql一个很让人不解的问题(关于编码)
- mysql 存储过程嵌套调用,在调用者中对被调用者返回的记录集进行处理,问题是如何再调用者中获得被调用者的记录集呢?临时表会不会速度太慢呢?
- mysql数据量较大的情况下如何做备份和恢复?
- 高分求教:数据库导入导出工具
- 如何判断是否建立了MYSQL的数据库
- [求组]db2中的with ... as (...) 在mysql中应该如何表示
- 添加外键约束的困惑
- navicat里如何用sql语句计算两列数值的差并自动填充到第三列
- 关于给函数默认参数和函数重载的问题。
- MySql两表联合查询,语句报错
desc v9_index;
desc v9_price;
....
v9_price
v9_picture
v9_video
v9_moble
v9_news
6个全部加上的话,就有下面图片这个问题
我有6个表,每个表的字段都不一样,我为了调用相同条件的内容,特别加了一个相同的字段为relate,就是为了把relate条件相同的内容调到一起的,请给个调用思路好吗?
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
-------------------------------------
id title url a b c d relate
-------------------------------------
1 数学 链接地址 3 4 6 7 关键字
-------------------------------------表2
-------------------------------------
id title url e f g h relate
-------------------------------------
2 语文 链接地址 3 4 5 8 关键字
-------------------------------------表3
------------------------------------
id title url i j k r relate
------------------------------------
3 英语 链接地址 3 5 8 6 关键字
------------------------------------
因为表一表二表三没有关联,所以我加了个字段:relate 增加关键字来关联的我想根据关键词来调用 title和url ,用前面的方法不成功的原因是,因为我三个表字段都不一样!!