%% Import All Data Using MySQL Native Interface
% Import all product data from a MySQL® database table into MATLAB® using the MySQL native interface and the fetch function. Then, determine the highest unit cost among products in the table.
%
% Create a MySQL native interface database connection to a MySQL database using a data source, user name, and password. The database contains the table productTable.

datasource = "MySQLNative";
username = "root";
password = "matlab";
conn = mysql(datasource,username,password);

%
% Import all the data from productTable by using the connection object and SQL query. Then, display the first three rows of the imported data.

sqlquery = "SELECT * FROM productTable";
data = fetch(conn,sqlquery);
head(data,3)

%
% Determine the highest unit cost for all products in the table.

max(data.unitCost)

%
% Close the database connection.

close(conn)

% Copyright 2020 The MathWorks, Inc.