TABLE: MENUS ------------ id int(11) url varchar(100) items varchar(35)
An example row:
ID URL ITEMS 158 programs/graduate 21,22,23,24,25,26,27,28,160
I want to select the ITEMS and then do another subselect that can uses each ITEM as the ID in the subselect.
'select items from menus where id = 158' returns:
21,22,23,24,25,26,27,28,160
Each of these ITEMS is an id in the table also. I want to get each row that corresponds to id = 21, 22, 23, 24, 25 ...
I know how to do this in php, but I need to do this on the command line. Remember that ITEMS is a varchar type, so I'm not sure if there's a way to do some kind of loop within this to select the items or create the long query string with OR id = 21 OR id = 22 OR id = 23 ... which I started to do:
select CONCAT('id = ', substring(items,1,LOCATE(',', items, 1)-1), ' OR id = ', substring(items, 4,locate(',', items,2)-1)) AS STR from menus where items != '' and id = 158;
but this can be pretty long since it only grabs the first two digits from ITEMS!
The ITEMS always has NO spaces between commas and numbers and some numbers may be single digit, two digits or even three in the row.
thanks in advance,
craig.
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]