user669677
user669677

Reputation:

mysql - give a query as value (dynamic value)

Can I give a query as a value in mysql?

I meen something like this:

UPDATE table1 SET val='X'

where

X= SELECT COUNT(page) AS X FROM table2 WHERE order_no=1

so every time I ask for X it should depend on other tables content

Upvotes: 0

Views: 201

Answers (1)

John Woo
John Woo

Reputation: 263783

You can do subquery for your value, example

UPDATE table1 
SET val = (
           SELECT COUNT(page) 
           FROM table2 
           WHERE order_no = 1
          )

Upvotes: 1

Related Questions