简体   繁体   中英

Conditionally execute query

Is there a way to execute a query, depending on the result of a certain column?

My table has a column col1 , which could be NULL . I want to check first. If col1 is not NULL, execute another query, if col1 is NULL, do nothing (or return something else).

In pseudocode it could look like this:

IF (SELECT col1 IS NUT NULL FROM `tab1`)
THEN (SELECT col1, col2, col3 FROM `tab1`)

PS: I execute those queries from PHP, so it would also be possible, to check the result of col1 with PHP, though I would prefer to use plain SQL.

the where clause is your if

  select col1, col2, col3 FROM `tab1`
  where col1 IS NOT NULL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM