Computer >> Máy Tính >  >> Lập trình >> MySQL

Làm thế nào để hiển thị một số cột (không phải tất cả) trong MySQL?

Để hiển thị một số cột, hãy sử dụng NOT IN và đặt những cột mà bạn không muốn hiển thị. Đầu tiên chúng ta hãy tạo một bảng. Sau đây là truy vấn -

mysql> create table student_Information
   -> (
   -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> StudentName varchar(50),
   -> StudentAge int,
   -> StudentAddress varchar(100),
   -> StudentAllSubjectScore int
   -> );
Query OK, 0 rows affected (0.69 sec)

Sau đây là truy vấn để hiển thị mô tả về bảng trên -

mysql> desc student_Information;

Điều này sẽ tạo ra kết quả sau -

+------------------------+--------------+------+-----+---------+----------------+
| Field                  | Type         | Null | Key | Default | Extra          |
+------------------------+--------------+------+-----+---------+----------------+
| StudentId              | int(11)      | NO   | PRI | NULL    | auto_increment |
| StudentName            | varchar(50)  | YES  |     | NULL    |                |
| StudentAge             | int(11)      | YES  |     | NULL    |                |
| StudentAddress         | varchar(100) | YES  |     | NULL    |                |
| StudentAllSubjectScore | int(11)      | YES  |     | NULL    |                |
+------------------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

Sau đây là truy vấn để chỉ hiển thị một số cột -

mysql> SHOW COLUMNS FROM student_Information where field not
in('StudentAddress','StudentAllSubjectScore');

Điều này sẽ tạo ra kết quả sau -

+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| StudentId   | int(11)     | NO   | PRI | NULL    | auto_increment |
| StudentName | varchar(50) | YES  |     | NULL    |                |
| StudentAge  | int(11)     | YES  |     | NULL    |                |
+-------------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)