MySQL不支持INTERSECT和MINUS,及其替代方法
Doing INTERSECT and MINUS in MySQL
By Carsten | October 3, 2005
Doing an INTERSECT
An INTERSECT is simply an inner join where we compare the tuples of one table with those of the other, and select those that appear in both while weeding out duplicates. So
SELECT member_id, name from a
INTERSECT
SELECT member_id, name from b
can simply be rewritten to
SELECT a.member_id, a.name
from a INNER JOIN b
USING (member_id, name)
Performing a MINUS
To transform the statement
SELECT member_id, name from a
MINUS
SELECT member_id, name from b
into something that MySQL can process, we can utilize subqueries (available from MySQL 4.1 onward). The easy-to-understand transformation is:
SELECT DISTINCT member_id, name
from a
WHERE (member_id, name) NOT IN
(SELECT member_id, name from table2);
Of course, to any long-time MySQL user, this is immediately obvious as the classical use-left-join-to-find-what-isn’t-in-the-other-table:
SELECT DISTINCT a.member_id, a.name
from a LEFT JOIN b USING (member_id, name)
WHERE b.member_id IS NULL
相关文档:
源地址: http://www.pcppc.cn/shujuku/mysql/shujuku_163919.html
您正在看的MySQL教程是:MySQL数据库学习笔记。
MySQL数据库学习笔记
(实验环境:Redhat9.0,MySQL3.23.54)
纲要:
一,连接MySQL
二,MySQL管理与授权
三,数据库简单操作
四, ......
1、mysql_connect()-建立数据库连接
格式:
resource mysql_connect([string hostname [:port] [:/path/to/socket] [, string username] [, string password]])
例:
$conn = @mysql_connect(”localhost”, “username”, “password”) or dir(”不能连接到Mysql Server” ......
1. 安装Cygwin
运行Cygwin的安装程序。从文见包的的列表中,在DEV里面,确定要选择
• Ruby
• gcc
• subversion
你需要使用gcc来建立Cygwin版本的MySQL.
2. 在windows上面安装MYSQL:
download MySQL 5.0 Windows Installer
3. & ......
MySQL日期字段分Date和Time两种,oracle日期字段只有Date,包含年月日时分秒信息,用当前数据库的系统时间为sysdate,精确到秒,或者用字符串转换日期型函数:
To_date('2001-08-01','YYYY-MM-DD'); 年-月-日
24小时:分钟:秒的格式 'YYYY-MM-DD HH24:MI:SS'  ......