mysql| statement since school so many years, has come to learn from an example is the fastest and most effective, and can cultivate a strong practical ability, which is a very
A good way to learn. Try not to visit. For example, when you look at a book, start with the examples from each chapter, and find out what you don't know and what you don't know or new knowledge.
And then targeted learning. Take a look at the following example:
From the above a small counter example to see. The knowledge of queries, inserts, and modifications has been included. can implement functionality. Record each IP's
The amount of traffic and the total number of visits. Total Not flush
First, inquiry:
Select is used to retrieve selected rows from one or more tables. Select_expression indicates the column you want to retrieve. Select can also be used
To retrieve a calculated row that does not reference any table
1, Select*from table1;
2, select Field1,field2 from table1;
3, select COUNT (*) from table2;
4, select Table1.filed1,table2.filed2 from Table1,table2 where table1.field1= ' valed1 ';
5. Select *from table1 where field1= ' valed1 ' and fiels2= ' Valed2 ' ' orded by field1;
6, Select*from table1 where filed1= ' valed1 ' order byfiled1 desc N;
7, select *from table2 where name like '% $lin% ';(blur)
8, Sub_selects (Advanced)
Select *from table1 where ID in (SELECT ID from table2 ...);
9, select ... into table ... High
(Available Select...into outfile ...; Insert...selkect ... Alternative
10, SELECT Max (field1) as field1 the maximum value from table1 column
Where: tables: Table \ fields: Field
Second, modify:
"Update table1 set field1= ' value1 ', field2=value2 ' where fiels3= ' values3 '";
Update updates the columns of rows in an existing table with the new value, the SET clause indicates which column to modify and what values they should be given, where clause, if
Given, specifies which row should be updated, otherwise all rows are updated.
Third, insert:
1, insert into table1 values (' field1 ', Field2 ',...);
INSERT ... Statements in the form of values insert rows based on a value that is explicitly specified.
2, replace into tbl_name (1,2,3) VALUES (' 1 ', ' 2 ', ' 3 ');
The Replace function is exactly the same as insert, except that if an old record in the table has the same value as a new record on a unique index
, the old record is deleted before the new record is inserted.
Four, delete:
$a = "delet from table1 where field1= ' $value 1 ' and field2= ' $value 2 '";
Delete Deletes rows from the Tbl_name table that meet the conditions given by where_definition, and returns the number of deleted records. If you hold
Row a delete with no WHERE clause, all rows are deleted.
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