0

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

1 Answer 1

1

You can do subquery for your value, example

UPDATE table1 
SET val = (
           SELECT COUNT(page) 
           FROM table2 
           WHERE order_no = 1
          )
Sign up to request clarification or add additional context in comments.

1 Comment

I got this: Warning: #1366 Incorrect integer value: '(SELECT COUNT(page) FROM table2 WHERE id=1)' for column 'fajlok_szama' at row 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.