Learning SQL, sorry if this is rudimentary. Trying to figure out a working UPDATE
solution for the following pseudo-language code:
UPDATE tableA SET tableA.col1 = '$var' WHERE tableA.user_id = tableB.id AND tableB.username = '$varName' ORDER BY tableA.datetime DESC LIMIT 1
The above is more like SELECT
syntax, but I'm basically trying to update a single column value in the last row of table A, where the username is found in the table name .B (named $ varName) is associated with its identification number in table B.id, which exists as an identifier in tableA.user_id.
Hope this makes sense. I assume some kind of JOIN
needed, but the subqueries seem unpleasant for UPDATE
. I understand that ORDER BY
and LIMIT
do not work when several tables are involved in UPDATE ... But I need functionality. Is there any way around this?
A little embarrassed, thanks in advance.
source share