MySQL variables in SELECT

Is it possible to have a query like:

SELECT @threadIDvar = `threads`.`id` AS `threadID`, (SELECT `posts`.`timeDate` FROM `posts` WHERE `posts`.`threadID` = @threadIDvar) AS `postDate` FROM `threads` INNER JOIN `posts` ON `posts`.`threadID` = `threads`.`id` WHERE `threads`.`boardID` = 1 

I tried this, but I get @threadID returned as NULL, and therefore postDate also as NULL.

How to get @threadIDvar variable to populate with returned thread id?

+4
source share
1 answer

Don't forget := for a variable, @threadIDvar := threads.id

+5
source

Source: https://habr.com/ru/post/1303329/


All Articles