Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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²»»á¹ýÂ˵ôÖØ¸´µÄÐÐ


Ïà¹ØÎĵµ£º

SpringÅäÖÃmysqlÊý¾Ý¿â


<! -- beans ÔªËØÊÇSpringÅäÖÃÎļþµÄ¸ùÔªËØ£¬ËùÓеÄSpring µÄÅäÖÃÎļþ¶¼Ó¦°´ÈçϽṹÊéдһ¡µ
<beans>
<!Ò»ÅäÖÃid ΪdataSource µÄbean£¬¸Ãbean ÊǸöÊý¾ÝԴʵÀýÒ»¡µ
<bean ¹¤d="dataSource" class="org.apache.corrunons.dbcp.BasicDataSource"
destroy-method="close">
<! È·¶¨Êý¾ÝÔ´µÄÇ ......

MYSQLÊý¾Ý¿âµ¼Èë¡¢µ¼³ö

1.mysqlµ¼³öÊý¾Ý¿âÃüÁî
C:\Program Files\MySQL\MySQL Server 5.0\bin>mysqldump -u Óû§Ãû -p Êý¾Ý¿âÃû (±íÃû) > c:\\ÎļþÃû.sql
2.mysqlµ¼ÈëÊý¾Ý¿âÃüÁî
£¨1£©½â¾öÖÐÎÄÂÒÂëÎÊÌ⣺ִÐÐÈçÏÂÃüÁîÔÙµ¼È룺set names utf8
£¨2£©µÇ¼mysql£¬Ö´ÐÐÈçÏÂÃüÁ
mysql> source c:\\ÎļþÃû.sql;
3½â¾öÖÐÎÄÂÒÂëÎÊÌ⣺ִР......

mySQL¼òµ¥´´½¨Êý¾Ý¿â¡¢±í¡¢¸Ä±äÊý¾Ý¿â·¾¶

´´½¨Êý¾Ý¿â£º
mysql>create database test;
Query OK, 1 row affected (0.02 sec)
´´½¨Êý¾Ý¿â±í£º
mysql>use test;
Database changed
´´½¨Êý¾Ý¿â±í£º
myaql>create table user(SID VARCHAR(11), name VARCHAT(6) );
Query OK, 0 rows affected (0.08 sec)
²åÈë¼Ç¼£º
mysql>insert int use ......

mysqlµÄÈýÖÖ°²×°·½Ê½

°²×°µÄOSΪSolaris10,mysql °æ±¾ÊÇ5.1.38
Ò»¡¢Ê¹ÓÃRPM°ü½øÐа²×°

    Ê×ÏÈ¿ÉÒÔ´Ó°²×°¹âÅÌÖлòÕßµ½mysqlµÄÍøÕ¾ÉÏÏÂÔØ¶ÔÓ¦°æ±¾µÄrpm°üÈçÏ£º
MySQL-server-community-5.1.38-0.rhel5.i386.rpm
MySQL-client-community-5.1.38-0.rhel5.i386.rpm
    ½Ó×ÅÎÒÃÇ¿ÉÒÔʹÓÃrpmÃü ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ