Here are two SQL statements. One is an select statement and the other is a update statement. I want to combine them.
Select
SELECT * FROM test WHERE `id`='1'
Update
UPDATE test SET `select_count`=`select_count`+'1' WHERE `id`='1'
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communityBased on your question I think you need to include SELECT
statement in UPDATE statement
:
Sample SQL in below:
create table test1
(ID int,
select_count int,
select_name varchar(50))
Insert into test1 values (1,1,'A')
Insert into test1 values (2,2,'B')
UPDATE test1
SET select_count = select_count + 1
where select_count = (SELECT select_count FROM test1 WHERE select_name = 'A')
Another way: If you have 2 tables (TableA and TableB)
UPDATE TableB
SET TableB.value = (
SELECT TableA.value
FROM TableA
WHERE TableA.name = TableB.name
)
where TableB.value < X;
*
?
Sep 30, 2018 at 19:29
*
)? Or you don't like to issue two commands? Or something else?