Welcome Guest, Not a member yet? Register   Sign In
Is it possible to do a `where id=(select id from table);` sql statement ?
#1

Hello,
I'd like to achieve this sql using the QueryBuilder class. Is it possible ?
Code:
UPDATE Series
  SET index = index+1
where index >= (SELECT index FROM Series WHERE field_id = 5)

-- or --

UPDATE Series
  SET index = ( SELECT max(index) FROM Series )
  WHERE field_id = 3

I'm currently using two different database calls (one select, one update), but since I'm using a very small amount of data, optimization is not a priority.
Actually learning CodeIgniter4 and creating a complex CMS system for fan-translations teams (Kagescan)
@LoganTann on GitHub // French // He-Him
Reply
#2

Well, let's say I'm being curious, but why don't you run the inner select queries first, store the value in a variable, then run the other select or update separately using the already existing value from the saved variable?
Reply
#3

Your query is too complex for the Query Builder. I think you should use query binding instead: https://codeigniter.com/user_guide/datab...y-bindings
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB