Ho usato una variabile chiamata @a, per memorizzare i ids, alla fine si hanno i valori della variabile o provare con un limite, l'ordine di gruppo da, in questo modo:
mysql> show create table actor\G
*************************** 1. row ***************************
Table: actor
Create Table: CREATE TABLE `actor` (
`actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`first_name` varchar(45) NOT NULL,
`last_name` varchar(45) NOT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`actor_id`),
KEY `idx_actor_last_name` (`last_name`)
) ENGINE=InnoDB AUTO_INCREMENT=207 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> set @a:=0;
Query OK, 0 rows affected (0.00 sec)
mysql> select @a:=concat(@a,",",actor_id) as actor_id from actor where actor_id>195 order by (actor_id) desc limit 1;
+----------------------------+
| actor_id |
+----------------------------+
| 0,196,197,198,199,200,205, |
+----------------------------+
1 row in set (0.00 sec)
Nella tua caso cambiare la "condizione WHERE"
o si può anche dopo il select:
mysql> select @a;
+-------------------------------+
| @a |
+-------------------------------+
| 0,196,197,198,199,200,205,206 |
+-------------------------------+
1 row in set (0.00 sec)
Sono piuttosto fortemente contro 'GROUP_CONCAT' - mi sembra un uso improprio di un motore di database. – jnylen
@jnylen - Non so perché, non ci sono note cautelative da parte della gente di MySQL, la domanda è stata codificata con MySQL, non con PHP. -Per ciascuno il suo amico, solo dicendo :) – GDP
@GregP Immagino che sia perché le operazioni del database devono manipolare e restituire tabelle di dati - non dovrebbero trattare tipi di dati "fasulli" come una stringa separata da virgole, quindi è una cattiva "codice odore" per me. Ogni volta che hai un elenco delimitato da virgole, dovresti probabilmente lasciarlo in righe o in un array. Ecco un buon esempio dei problemi che si possono affrontare: http: // StackOverflow.it/questions/6643656/mysql-comma-delimited-list-possible-to-add-and-remove-values? rq = 1 – jnylen