【问题标题】:mySQL Variables in SELECTSELECT 中的 mySQL 变量
【发布时间】:2010-03-06 11:00:51
【问题描述】:

是否可以进行如下查询:

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

我已经尝试过了,但我得到 @threadID 返回为 NULL,因此 postDate 也为 NULL。

如何让变量@threadIDvar 填充返回的线程ID?

【问题讨论】:

    标签: sql mysql tsql


    【解决方案1】:

    不要忘记 :=user variable ,@threadIDvar:=threads.id

    【讨论】:

    • 啊...我忘了...谢谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 2013-03-12
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    相关资源
    最近更新 更多