SQL语句关键字UNION小知识
今天在用UNION进行将两个查询结合时,发现加了text类型的字段进去就报错了,错误信息如下:
不能以 DISTINCT 方式选择 text、ntext 或 image 数据类型。
经过翻阅资料后才知道,原因在于如此操作 无法对text类型判断是否重复,所以要在UNION后加个ALL关键字,如下:
select top 6 * from
(select top 6 a.content,b.title, b.takenoticeid ID,b.taketime,type = 1 from takenotice_content as a,
(select * from comm_takenotice_201004 where takeperson = 'g567890' )as b
where a.contentid = b.contentid and b.readstatus ='0'
union all
select top 6 a.content,title = '', b.takesmsid ID,b.taketime,type = 2 from takesms_content as a,
(select * from comm_takesms_201004 where takeperson = 'g567890')as b
where a.contentid = b.contentid ) x order by taketime desc
如需按某一条件排序,则要加别名,如上面sql中的x,方可执行。
相关文档:
SQL字符串函数http://www.cnblogs.com/virusswb/archive/2008/09/10/1288576.html
select语句中只能使用sql函数对字段进行操作(链接sql server),
select 字段1 from 表1 where 字段1.IndexOf("云")=1;
这条语句不对的原因是indexof()函数不是sql函数,改成sql对应的函数就可以了。
left()是sql函数。
select 字 ......
Magento是在Zend Framework的基础上搭建而来,有两种方式可以从Magento的collection获得真正的SQL语句。
以 Mage::getResourceModel('reports/product_collection') 为例:
1
$collection=Mage::getResourceModel('reports/product_collection');
......
一、 先介绍一下oracle的SGA:数据库的系统全局区,SGA主要由三部分构成:共享池、数据缓冲区、日志缓冲区。 1、共享池又由两部分构成:共享SQL区和数据字典缓冲区。共享SQL区专门存放用户SQL命令,oracle使用最近最少使用等优先级算法来更新覆盖;数据字典缓冲区(library cache)存放数据库运行的动态信息。数据库运行一 ......
数据库操作类:
复制代码 代码如下:
/// <summary>
/// 取得总数
/// </summary>
/// <returns></returns>
public string getTotal()
{
StringBuilder sb = new StringBuilder();
sb.Append("select count(*) total from Test");
DataTable dt = DBHelper.ExecuteDt(sb.ToString ......