Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MySQL

Mô phỏng biến mảng trong MySQL

MySQL không có mảng, dùng TEMPORARY TABLE thay thế.

Cú pháp:

create temporary table if not exists yourTemporaryTableName select yourColumnName1,yourColumnName2,... from yourTableName where condition

Tạo bảng SimulateArrayDemo (Id, FirstName, LastName), chèn 6 bản ghi.

Tạo temporary table lọc LastName='Taylor':

mysql> create temporary table if not exists SimulationOfArray
-> select Id,FirstName from SimulateArrayDemo where LastName='Taylor';
Query OK, 4 rows affected (0.10 sec)

Kết quả 4 hàng (Sam, Carol, David, Mike).