Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql's method of querying all columns in a table

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article shares with you about the methods of querying all the columns in the mysql table. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

Mysql query all columns in the table: 1, through "*" query all columns of the table, syntax "SELECT * FROM table name;"; 2, query all columns of the table by listing all the fields of the table, syntax "SELECT field list FROM table name;".

A MySQL data table is made up of rows and columns. The "column" of the table is usually called a Field, and the "row" of a table is called a Record.

Query all columns (fields) in the table

Querying all fields refers to the data of all fields in the query table. MySQL provides the following two ways to query all fields in a table.

Query all fields using the "*" wildcard

List all fields of the table

1) use "*" to query all fields of the table

SELECT can use "*" to find data for all fields in the table. The syntax format is as follows:

SELECT * FROM table name

When using a "*" query, you can only arrange the fields in the order of the data table, not change the order of the fields.

Example 1

Query the data for all fields from the tb_students_info table, and the SQL statement and run results are shown below.

Mysql > use test_db;Database changedmysql > SELECT * FROM tb_students_info +-+ | id | name | dept_id | age | sex | height | login_date | + -+-+ | 1 | Dany | 1 | 25 | F | 2015 | 09-10 | 2 | Green | 3 | 23 | F | 2016-10-22 | 3 | Henry | 2 | 23 | M | 2015-05-31 | 4 | Jane | 1 | 22 | F | 2016-12-20 | 5 | | Jim | 1 | 24 | M | 2016 | 01-15 | | 6 | John | 2 | 21 | M | 2015 | 11-11 | | 7 | Lily | 6 | 22 | F | 2016-02-26 | 8 | Susan | 4 | 23 | F | 2015-10-01 | 9 | Thomas | 3 | 22 | M | 2016-06-07 | | | 10 | Tom | 4 | 23 | M | 165,165 | 2016-08-05 | +-+ 10 rows in set (0.26sec) |

The result shows that when you use the "*" wildcard, all columns are returned, and the data columns are displayed in the order in which the table was created.

Note: in general, it is best not to use the wildcard "*" unless you need to use all the field data in the table. Although using wildcards can save time entering query statements, getting unwanted column data usually reduces the efficiency of the query and the application used. The advantage of using "*" is that when you don't know the names of the columns you want, you can get them through "*".

2) list all fields of the table

The field after the SELECT keyword is called the field you want to find, so you can follow the names of all fields in the table after the SELECT keyword.

SELECT field list FROM table name

If you forget the field name, you can use the DESC command to view the structure of the table.

Sometimes, because there are so many fields in the table, you may not be able to remember the names of all the fields, so this method is inconvenient and is not recommended.

Example 2

To query all the data in the tb_students_info table, the SQL statement can also be written as follows:

SELECT id,name,dept_id,age,sex,height,login_date FROM tb_students_info

The running result is the same as in example 1.

This query method is more flexible. If you need to change the order in which the fields are displayed, you only need to adjust the order of the list of fields after the SELECT keyword.

Although it is flexible to list all the fields of a table, the "*" wildcard is usually used when querying all fields. Using the "*" approach is relatively simple, especially when there are a lot of fields in the table, the advantage of this approach is more obvious. Of course, if you need to change the order in which the fields are displayed, you can choose to list all the fields in the table.

Thank you for reading! This is the way to share all the columns in the mysql query table. I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report