Getting started with mysql (4)

xiaoxiao2021-03-06  69

Mysql Getting Started (4) Learning Articles (2) (Add Time: 2002-3-25 Hits: 3312)

ABCCS

Learn article on the article I learned how to create a database and database table and know how to add a record to the database table. So how do we retrieve data from the database table? 1. Retrieve information from the database table In fact, we have used the SELECT statement, which is used to retrieve information from the database table. The SELECT statement format is generally: Select Retrieves Keyword from Htroke WHERE Retrieval Condition (optional) Previously "*" indicates all columns. Let's continue using our table MyTable: 2, query all data: mysql> select * from myTable; ---------- ---- ---- -------- ---------- | Name | SEX | BIRTH | BIRTHADDR | ---------- ---- - ---------- -------- | ABCCS | F | 1977-07-07 | China | | MARY | F | 1978-12-12 | USA | | Tom | M | 1970-09-02 | USA | ---------- ------ -------- --------- - 3 ROW IN Set (0.00 sec) 3, correct error record: If Tom has an error, it should be 1973-09-02, you can use the UPDATE statement to correct: mysql> Update myTable set birth = "1973- 09-02 "where name =" Tom "; use the statement in 2 to see if it is correct. 4, select the specific line to modify TOM birth date, we can choose Tom to see if there is already changed: mysql> select * from myTable where name = "Tom"; ------------ ---- ------------ ------------ | Name | SEX | BIRTH | BIRTHADDR | ------ - ------ ------------ ---------- | Tom | M | 1973-09-02 | USA | -------- ------ ------------ ---------- 1 ROW IN Set (0.06 sec) The parameters of the above WHERE specifies the search criteria.

We can also use combination conditions to query: mysql> select * from myTable where sex = "f" and birthaddr = "China"; -------- ------ ---- -------- ------------ | Name | SEX | BIRTH | BIRTHADDR | -------- ---- - ---------- ------------ | ABCCS | F | 1977-07-07 | China | -------- --- - ------------ ------------ 1 ROW IN Set (0.06 sec) 5, choose a specific column, if you want to view the table You can do this, you can do this: mysql> select name from myTable; ---------- | Name | ---------- | ABCCS | | MARY | | Tom | ---------- 3 Row in Set (0.00 sec) If you want to list both name and gender, you can separate keywords Name and Birth with a comma: myaq> select name, Birth from myTable; 6, sorting the line We can sort the records in the table: mysql> select name, birth from mytable order by birth; -------- - --------- | Name | Birth | ---------- ------------ | Tom | 1973-09-02 | ABCCS | 1977-07-07 | | Mary | 1978-12-12 | ---------- ---------- 3 Row in set (0.00 sec) We can use DESC to sort in reverse sequence: mysql> Select name, birth from mytable order by birth desc; -------- ---------- | Name | Birth | ---------- ------------ | Mary | 1978-12-12 | | ABCCS | 1 977-07-07 | | Tom | 1973-09-02 | ---------- ------------ 3 Row In Set (0.00 sec) 7, Bank count databases often count some data, such as the number of employees in the table, we must use the line count function count ().

转载请注明原文地址:https://www.9cbs.com/read-121256.html

New Post(0)