MySQL Initial learning

Source: Internet
Author: User

Use of 1.insert_select: Copy data from one table to another

INSERT into students (name,sex,likebooksnum,likesportnum,average)
SELECT
Name,sex,likebooksnum,likesportnum,average
From Students_copy;2.regexp: Use of regular expressions, BINARY is a case-sensitive search

Select students. ' Name ' from students WHERE students. ' Name ' REGEXP BINARY ' Jack ';

3. Aggregate function, COUNT (*), as table alias, GROUP By,with ROLLUP

SELECT Sex, COUNT (*) as Sex_num from students GROUP by sex with ROLLUP;

4, left outer junction left/right OUTER JOIN table column name on junction: Select All rows on the left/right: For example, you can retrieve some columns with a value of NULL

SELECT students. ' Name ', Students.sex,count (sorce.average) as Average_num
From students left OUTER JOIN sorce on Students.average=sorce.average GROUP by students.name;5, using trigger: CREATE TRIGGER (Trigger) A fter INSERT on students_copy updated table for each ROW update execution update means (Students_count SET students_count=students_count+1)

CREATE TRIGGER newname after INSERT on students_copy for each ROW
UPDATE Students_count set students_count=students_count+1;6,update the table set operation directives to manipulate the WHERE query condition: It is important to note that the column name is to avoid the MySQL keyword, For example: name, etc.;

UPDATE students_copy
SET ' students_name ' = "David" WHERE average=100;7, joins table operations, makes operation easier

SELECT
Students. ' Name '
From Students,sorce,books
where Students.average=sorce.average and Sorce.id=books.id and books.id=161034168, the self-junction of the table:

SELECT s1.name,s1.average from students as s1,students as S2 WHERE s1. ' Name ' =s2. ' Name ' and S1. likebooksnum=3;

MySQL Initial learning

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.