%% Import Data Using Row Limit
% Use the MATLAB® interface to SQLite to import a limited number of rows into MATLAB® from a database table in an SQLite database file. Then, determine the highest unit cost among products in the table.
%
% Create the SQLite connection conn to the existing SQLite database file tutorial.db. The database file contains the table productTable. conn is an sqlite object.

dbfile = 'tutorial.db';

conn = sqlite(dbfile);

%
% Import five rows of data from productTable by using the rowlimit argument. results contains five rows of imported data as a cell array.

sqlquery = 'SELECT * FROM productTable';
rowlimit = 5;
results = fetch(conn,sqlquery,rowlimit)

%
% Determine the highest unit cost for the limited number of products. Access unit cost data by looping through the fourth column of the cell array. data is a vector that contains numeric unit costs. Find the maximum unit cost.

for i = 1:rowlimit
    data(i) = results{i,4};
end
max(data)

%
% Close the SQLite connection.

close(conn)