Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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²»»á¹ýÂ˵ôÖØ¸´µÄÐÐ


Ïà¹ØÎĵµ£º

MySQL ÖÐÎÄÏÔʾÂÒÂë

×î½ü¹ØÓÚÖÐÎÄÏÔʾÂÒÂëµÄÌù×ӱȽ϶࣬ËùÒÔÒ²×öÁ˸ö×ܽ᣺
¿ÉÒԲο¼Ò»ÏÂÑîÌÎÌΰæÖ÷µÄ¡¶¸÷ÖÖÂÒÂëÎÊÌâ»ã×Ü¡·
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
²»Í¬µÄ±àÂë¸ñʽ»áµ¼ÖÂͬһ×Ö· ......

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


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

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ÖвåÈëÒ»Ìõ¼Ç¼·µ»Ø¸Ã¼Ç¼id

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ÃüÁî

1. Á¬½Ómysql:
mysql -h Ö÷»úµØÖ· -u Óû§Ãû £­p
2.Í˳ömysql:exit
3. ÐÞ¸ÄÃÜÂë:
mysqlbinmysqladmin -uroot -p(oldpassword) password newpassword
4.Ôö¼ÓÓû§£º
Ìí¼ÓÒ»¸öÓû§test1 ÃÜÂëΪABC£»ÈÃËû¿ÉÒÔÔÚÈκÎÖ÷»úÉϵǼ,²¢¶ÔËùÓÐÊý¾Ý¿âÓвéѯ¡¢²åÈë¡¢Ð޸ġ¢É¾³ýµÄȨÏÞ¡£Ê×ÏÈÓÃÒÔrootÓû§Á¬Èë
mysql,È»ºó¼üÈëÒÔÏÂÃü ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ