mysqlÖеÄunionºÍorder by¡¢limit
ÎÒÓÐÒ»¸ö±í
CREATE TABLE `test1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`desc` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
£¨1£©ÒÔϲéѯ»á±¨´íÎó£º[Err] 1221 - Incorrect usage of UNION and ORDER BY
select * from test1 where name like 'A%' order by name
union
select * from test1 where name like 'B%' order by name
Ó¦¸ÄΪ£º
select * from test1 where name like 'A%'
union
select * from test1 where name like 'B%' order by name
ÒòΪunionÖУ¬ÔÚ²»ÓÃÀ¨ºÅµÄÇé¿öÏ£¬Ö»ÄÜÓÃÒ»¸öorder by£¨ÏëÒ»Ï룬Èç¹ûunionÁ½±ßµÄorder byµÄÁÐÃû²»Ò»Ñù»áÔõôÑù£©,Õâ»á¶ÔunionºóµÄ½á¹û¼¯½øÐÐÅÅÐò
»òÕ߸ÄΪ£º
£¨select * from test1 where name like 'A%' order by name£©
union
£¨select * from test1 where name like 'B%' order by name£©
ÕâÁ½¸öorder byÔÚunionÇ°½øÐÐ
£¨2£©Í¬ÑùµÄ
select * from test1 where name like 'A%' limit 10
union
select * from test1 where name like 'B%' limit 20
Ï൱ÓÚ
£¨select * from test1 where name like 'A%' limit 10£©
union
£¨select * from test1 where name like 'B%'£© limit 20
¼´ºóÒ»¸ölimit×÷ÓÃÓÚµÄÊÇunionºóµÄ½á¹û¼¯£¬¶ø²»ÊÇunionºóµÄselect
Ò²¿ÉÒÔ¼ÓÀ¨ºÅÀ´µÃµ½ÄãÏëÒªµÄ½á¹û
£¨select * from test1 where name like 'A%' limit 10£©
union
£¨select * from test1 where name like 'B%' limit 20£©
£¨3£©UNIONºÍUNION ALLÇø±ð
union»á¹ýÂ˵ôunionÁ½±ßµÄselectµÃµ½µÄ½á¹û¼¯ÖеÄÖظ´µÄÐУ¬¶øunion all²»»á¹ýÂ˵ôÖظ´µÄÐÐ
Ïà¹ØÎĵµ£º
×î½ü¹ØÓÚÖÐÎÄÏÔʾÂÒÂëµÄÌù×ӱȽ϶࣬ËùÒÔÒ²×öÁ˸ö×ܽ᣺
¿ÉÒԲο¼Ò»ÏÂÑîÌÎÌΰæÖ÷µÄ¡¶¸÷ÖÖÂÒÂëÎÊÌâ»ã×Ü¡·
http://topic.csdn.net/u/20071124/08/3b7eae69-ed1d-4a77-8895-9930bf3601af.html
MySQL×Ö·û¼¯µÄÔÀí½éÉÜ¡£ÕªÂ¼ÓÚ¹Ù·½Îĵµ¡£http://dev.mysql.com/doc/refman/5.1/zh/charset.html
²»Í¬µÄ±àÂë¸ñʽ»áµ¼ÖÂͬһ×Ö· ......
====================================================
Òý×Ô£ºhttp://blog.sina.com.cn/s/blog_538a9d1901008f9g.html
ʲôÊÇC2¼¶°²È«ÐÔ£¿°²È«ÐԵķÖÀàÊÇÔõÑùµÄ£¿(2008-01-30 17:04:39)
DÀࣺ×îµÍ±£»¤£¬±£Áô¸ø²»ÄÜͨ¹ý¸ü¸ß¼¶±ð¼ì²éµÄϵͳ
C1£º½÷É÷±£»¤£¬ÒªÇóÓлùÓÚÓû§¼¶±ðµÄ¿ØÖÆÀ´±£»¤Êý¾Ý£¬Ö÷Òª·ÀÖ ......
·µ»ØÀ´×ÔÓÚ²ÎÊýÁ¬½áµÄ×Ö·û´®¡£Èç¹ûÈκβÎÊýÊÇNULL£¬·µ»ØNULL¡£¿ÉÒÔÓг¬¹ý2¸öµÄ²ÎÊý¡£Ò»¸öÊý×Ö²ÎÊý±»±ä»»ÎªµÈ¼ÛµÄ×Ö·û´®ÐÎʽ¡£
mysql> select CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql> select CONCAT('My', NULL, 'QL');
-> NULL
mysql> select CONCAT(14.3);
-> '14.3'
È磺update test set ......
¡¾ÊéÃû¡¿¸ßÐÔÄÜMySQL£¨µÚ¶þ°æ£©
¡¾ÔÊéÃû¡¿High Performance MySQL, second edition
¡¾×÷Õß¡¿Baron Schwartz£¬Peter Zaitsev£¬Vadim
Tkachenko£¬Jeremy D.Zawodny£¬Arjen Lentz£¬Derek
J.Balling Öø
¡¾ÒëÕß¡¿ÍõС¶« Àî¾ü ¿µ½¨Ñ« Òë
¡¾³ö°æÉç¡¿µç×Ó¹¤Òµ³ö°æÉç
¡¾ÊéºÅ¡¿978- ......
1.select max(id) from user;
2.select last_insert_id() as id from user limit 1;
(Õâ¸ö²âÊԵķµ»ØidÒ»Ö±ÊÇ0£¬ÓеãÎÊÌâ)
3.´¢´æ¹ý³Ì
1£©
oracelÖÐ
create sequence seqID
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
nocache
order;
create or replace procedure ......