sql_in_select

The function sql_in_select() returns a sql_in from the result of a sql_select.

It accepts the same arguments as sql_select plus one additional parameter in first place:

  1. $in is the name of the column on which the IN will be applied,
  2. $select,
  3. $from,
  4. $where,
  5. $groupby,
  6. $orderby,
  7. $limit,
  8. $having,
  9. $serveur,
  10. $option.

You can use it like this:

$where = sql_in_select("column", "column", "tables", "id_parent = $id_parent"));
// $where: column IN (3, 5, 7)
if ($res = sql_select('column', 'another_table', $where)) {
	// ...
}

Example

Delete every link between an article and the keywords of a given keyword group:

sql_delete("spip_mots_articles", array(
		"id_article=" . $id_article,
		 sql_in_select("id_mot", "id_mot", "spip_mots", "id_groupe = $id_groupe"));

Author Gilles Vincent Published : Updated : 12/03/23

Translations : English, français