Home > database > mysql_unique_fld_vals.m

mysql_unique_fld_vals

PURPOSE ^

Returns a sorted list of unique values in a specific field of a specific table

SYNOPSIS ^

function [fld_vals] = mysql_unique_fld_vals(tbl_name, fld_name, conn_id)

DESCRIPTION ^

 Returns a sorted list of unique values in a specific field of a specific table
 [fld_vals] = mysql_unique_fld_vals(tbl_name, fld_name, conn_id);

 conn_id - connection to database - required

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [fld_vals] = mysql_unique_fld_vals(tbl_name, fld_name, conn_id)
0002 % Returns a sorted list of unique values in a specific field of a specific table
0003 % [fld_vals] = mysql_unique_fld_vals(tbl_name, fld_name, conn_id);
0004 %
0005 % conn_id - connection to database - required
0006 
0007 % 08/18/05 Petr Janata
0008 % 01/03/07 PJ - removed dependency on unique()
0009 % 06/15/10 PJ - sanitized mysql_make_conn()
0010 
0011 
0012 % Do some input parameter checking.
0013 % Modify min_arg and max_arg accordingly for your function
0014 min_arg = 2;
0015 max_arg = 3;
0016 
0017 msg = nargchk(min_arg,max_arg,nargin);
0018 if ~isempty(msg)
0019   disp(msg)
0020   return
0021 end
0022 
0023 % Check for valid connection to database
0024 if ~exist('conn_id','var') || isempty(conn_id) || mysql(conn_id,'status')
0025   error('%s: Do not have a valid connection ID', mfilename);
0026 end
0027 
0028 mysql_str = sprintf('SELECT DISTINCT %s FROM %s', fld_name, tbl_name);
0029 fld_vals = mysql(conn_id, mysql_str);

Generated on Sat 25-May-2019 04:00:51 by m2html © 2003