Beginner MySQL Basic syntax

Source: Internet
Author: User

1 SELECT *  fromnew;2 SELECTStuname fromNew//Querying a column3 SELECT DISTINCTStuname fromNew//querying for different values in the same column4 SELECTColumn Name fromTable nameWHEREcolumn operator value;//conditionally querying the value of a column5 SELECTStuname,stuage fromNewWHEREStuname<> 'should fly'  andStuage=  A;//This symbol means not equal to<>Or!=6 SELECT *  fromYxfdb.newWHEREStuageinch(' A',' at');//inoperator allows us toWHEREspecify multiple values in a clause7 SELECT *  fromYxfdb.newWHEREStuage not between  A  and  -;//Operatorbetween... andA range of data between two values is selected. These values can be numeric, text, or date. 8 SELECT *  fromYxfdb.newWHEREStuname not  like '%xf%';//Using the LIKE query keyword,'y%'Y start with,'%y'Y end of the,'%xf%'contains the XF's9 SELECTStuname,stuage fromNewORDER  byStuname,stuage;//ORDER  byare letters and numbers sorted by default from small to largeTen SELECTStuname,stuage fromNewORDER  byStunameDESC, StuageASC;//DESCis sorted in reverse order, ASC is sorted by small to large One SELECTStuname,stuage fromYxfdb.new LIMIT5;//Query the first five data A SELECTNe.stuname, Ne.stuage fromYxfdb.new asNeWHERENe.stuname='should fly'  andNe.stuage=' -';//use as aliases to make the query program easier to read and write -  - SELECTYxfdb.new.stuname, Yxfdb.new.stuage, Yxfdb.info. ' Name ' the  fromYxfdb.info - INNER JOINyxfdb.new -  onYxfdb.info.id=yxfdb.new.id - ORDER  byYxfdb.new.stuname;// JOIN(INNERJoins within join intersection Left( Right) Join LEFT join whichever is right or not, take out the left. Fulljoin fetch set) +  - SELECTE_name fromEmployees_china + UNION A SELECTE_name fromEmployees_usa//UNIONoperator is used to merge two or moreSELECTThe result intersection of the statement,UNION  Allis the set at  -SqlSELECT  intostatement can be used to create a backup copy of a table.  -  -  -  - INSERT  intoYxfdb.new (Stuname,stuage)VALUES('XF',' -'); in  -  to UPDATETable nameSETColumn Name=New valueWHEREColumn Name=a value;//Modify a row of data + UPDATEYxfdb.newSETStuname='Zhang San' WHEREId= 2 ; -  the  * DELETE  fromTable nameWHEREColumn Name=Value//Delete a column's value $ DELETE  fromYxfdb.newWHEREId= 1 ;Panax Notoginseng  -  the ALTER TABLEtable_nameADDCOLUMN_NAME datatype;//Add a column + ALTER TABLEtable_nameDROP COLUMNcolumn_name;//Delete a column A ALTER TABLEtable_nameALTER COLUMNcolumn_name date;//Modify the data type of a column the ALTER TABLEPersonsADD PRIMARY KEY(id_p);//Modify Id_p Primary key +  - CREATE DATABASEmy_db $  $ CREATE TABLEOrders - ( -Id_oint  not NULL, theOrderNoint  not NULL, -Id_pint,Wuyi PRIMARY KEY(id_o), the FOREIGN KEY(id_p)REFERENCESPersons (id_p) -)//Create tables and set primary and foreign keys Wu  -  About ALTER TABLESocial $ ADD FOREIGN KEY(id_p) - REFERENCESinfo (id_p);// -  - CREATE TABLEPersons A ( +Id_pint  not NULL PRIMARY KEY, theLastNamevarchar(255), -FirstNamevarchar(255), $Addressvarchar(255), theCityvarchar(255), the UNIQUE(id_p) the ) the  -  in It is also possible to select data from more than one table.  the The following example creates a new table named "Persons_order_backup" that contains the information obtained from the Persons and Orders two tables: the SELECTPersons.lastname,orders.orderno About  intoPersons_order_backup the  fromPersons the INNER JOINOrders the  onPersons.id_p=Orders.id_p

Beginner MySQL Basic syntax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.