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²»»á¹ýÂ˵ôÖØ¸´µÄÐÐ
Ïà¹ØÎĵµ£º
MySQL ClusterÅäÖÃstep by step
À´Ô´£ºhttp://space.itpub.net/15415488/viewspace-620903
¹«Ë¾ÓиöÏîÄ¿ÊDzâÊÔdistributed DB£¬ÆäÖÐÒ»ÏîÊÇÕë¶ÔMySQL ClusterµÄ²âÊÔ¡£
ÓÚÊÇ»¨ÁËÁ½Ììʱ¼ä×°»úÆ÷ºÍÅäÖÃMySQL Cluster¡£Õû¸ö¹ý³Ì»¹ÊDZȽÏ˳ÀûµÄ£¬µ±È»Èç¹û¶ÔMySQL³£ÓÃÃüÁî±È½ÏÊìϤµÄ»°»á¸ü˳Àû¡£
ÁôÏÂstep by stepÅä ......
create database sample;
create table 't_user' (
'id' int(11) not null auto_increment,
'name' varchar(100) not null default '',
primary key ('id')
) type=myisam;
Ñ¡ÏîÖ»ÔÚMySQL 3.23ºÍÒÔºó°æ±¾Öб»ÊµÏÖ¡£
²»Í¬µÄ±íÀàÐÍÊÇ£º
ISAM ÔÀ´µÄ±í´¦ÀíÆ ......
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 ......
MySQL´æ´¢¹ý³ÌµÄ²ÎÊýÓÃÔÚ´æ´¢¹ý³ÌµÄ¶¨Ò壬¹²ÓÐÈýÖÖ²ÎÊýÀàÐÍ,IN,OUT,INOUT,ÐÎʽÈ磺
CREATE PROCEDURE([[IN |OUT |INOUT ] ²ÎÊýÃû Êý¾ÝÀàÐÎ...])
1¡¢IN ÊäÈë²ÎÊý:±íʾ¸Ã²ÎÊýµÄÖµ±ØÐëÔÚµ÷Óô洢¹ý³Ìʱָ¶¨£¬ÔÚ´æ´¢¹ý³ÌÖÐÐ޸ĸòÎÊýµÄÖµ²»Äܱ»·µ»Ø£¬ÎªÄ¬ÈÏÖµ
2¡¢OUT Êä³ö²ÎÊý:¸ÃÖµ¿ÉÔÚ´æ´¢¹ý³ÌÄÚ²¿±»¸Ä±ä£¬²¢¿É·µ»Ø
3¡¢I ......