The unique in MySQL

Source: Internet
Author: User

Distinct can remove duplicate lines, query time with SELECT DISTINCT * from ...;

Unique is one of the integrity constraints in MySQL and adds a unique constraint if the value of a column needs to be unique.

The purpose of creating a unique index is not to increase access speed, but to avoid duplication of data. A unique index can have more than one but the value of the indexed column must be unique, and the value of the indexed column allows for a null value. If you can determine that a data column will contain only values that are different from each other, you should use the keyword unique when creating an index for that data column and define it as a unique index.

* The difference between truncate and delete:
* Truncate DELETE data, delete entire table first. Create a new empty table again. Efficiency
* Delete Deletes data, one by one deleted. (*****)

* Group BY group (used together) conditional filtering needs to be having, cannot use where
Exercise: After classifying the items in the order form, the total price of each type of item is displayed.
Select Product,count (*), SUM (price) from the orders group by product;

Exercise: Find items that have purchased several categories of goods, and each category has a total price greater than 100
Select Product,sum (Price) from the orders group by product have sum (price) > 100;


* Summary SELECT statement: S-f-w-g-h-o combination Select ... from ... where ... a group by ....; Order by ...;
Order cannot be changed

The unique in MySQL

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.