开发者

mySQL Variables in SELECT

开发者 https://www.devze.com 2022-12-22 15:15 出处:网络
Is it possible to have a query such as the following: SELECT @threadIDvar = `threads`.`id` AS `threadID`,

Is it possible to have a query such as the following:

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 have tried it but I get @threadID returned as NULL开发者_JS百科 and consequently postDate also as NULL.

How do I get the variable @threadIDvar to be filled with the returned threadID?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号