資源描述:
《mysql經(jīng)典語(yǔ)句總結(jié)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫(kù)。
1、PHPer.yang文章整理集合MySQL經(jīng)典語(yǔ)句總結(jié)(侯惠陽(yáng)PHPer.yang)SELECTSELECT列名稱FROM表名稱SELECTLastName,FirstNameFROMPersonsSELECT*FROMPersonsSELECTDISTINCT列名稱FROM表名稱SELECTDISTINCTCompanyFROMOrders//去除重復(fù)的distinctWHERESELECT列名稱FROM表名稱WHERE列運(yùn)算符值SELECT*FROMPersonsWHERECity='Beijing'SELECT*FROMPe
2、rsonsWHEREYear>1965INSERTINTOINSERTINTO表名稱VALUES(值1,值2,....)INSERTINTOtable_name(列1,列2,...)VALUES(值1,值2,....)INSERTINTOPersonsVALUES('Gates','Bill','Xuanwumen10','Beijing')INSERTINTOPersons(LastName,Address)VALUES('Wilson','Champs-Elysees')Insertintotable()select*from
3、name;//直接讀取數(shù)據(jù)插入數(shù)據(jù)UpdateUPDATE表名稱SET列名稱=新值WHERE列名稱=某值UPDATEPersonSETFirstName='Fred'WHERELastName='Wilson'UPDATEPersonSETAddress='Zhongshan23',City='Nanjing'WHERELastName='Wilson'DELETEDELETEFROM表名稱WHERE列名稱=值DELETEFROMPersonWHERELastName='Wilson'DELETEFROMtable_nameORD
4、ERBYSELECTCompany,OrderNumberFROMOrdersORDERBYCompanySELECTCompany,OrderNumberFROMOrdersORDERBYCompany,OrderNumberSELECTCompany,OrderNumberFROMOrdersORDERBYCompanyDESCSELECTCompany,OrderNumberFROMOrdersORDERBYCompanyDESC,OrderNumberASCAND&ORSELECT*FROMPersonsWHEREFirs
5、tName='Thomas'ANDLastName='Carter'SELECT*FROMPersonsWHEREfirstname='Thomas'ORlastname='Carter'侯惠陽(yáng)PHPer.yang文章整理集合SELECT*FROMPersonsWHERE(FirstName='Thomas'ORFirstName='William')ANDLastName='Carter'INSELECT列名稱FROM表名稱WHERE列名稱IN(值1,值2,..)SELECT*FROMPersonsWHERELastNameIN
6、('Adams','Gates')BETWEEN...ANDSELECT列名稱FROM表名稱WHERE列名稱BETWEEN值1AND值2SELECT*FROMPersonsWHERELastNameBETWEEN'Adams'AND'Carter'SELECT*FROMPersonsWHERELastNameNOTBETWEEN'Adams'AND'Carter'AliasSELECT列名稱AS列的別名FROM表名稱SELECT列名稱FROM表名稱AS表的別名SELECTLastNameASFamily,FirstNameASNa
7、meFROMPersonsSELECTLastName,FirstNameFROMPersonsASEmployeesJoinSELECT*FROMtx1leftjoin(tx2,tx3)ON(tx1.id=tx2.tidANDtx2.tid=tx3.tid)wheretx1.id=3SELECT*FROMt1LEFTJOIN(t2,t3,t4)ON(t2.a=t1.aANDt3.b=t1.bANDt4.c=t1.c)等價(jià)于:SELECT*FROMt1LEFTJOIN(t2CROSSJOINt3CROSSJOINt4)ON(t2.
8、a=t1.aANDt3.b=t1.bANDt4.c=t1.c)在MySQL中,CROSSJOIN語(yǔ)法上等價(jià)于INNERJOIN(它們可以彼此代替。在標(biāo)準(zhǔn)SQL中,它們不等價(jià)。INNERJOIN結(jié)合ON子句使用;CROSSJOIN用于其它地方。SEL