我的 SQL 查询有问题。我得到了以下查询,这是非常基本的:
SELECT *
FROM table1
WHERE Date = CURDATE()
table1 中有一个名为 h_id
的列,还有一个 table2
,其中包含 h_id
列和 name
我想连接这两个表,以便获得表 2 中当前日期的姓名。
我试过了,但似乎不起作用
SELECT t2.name, t1.field2
FROM table1 t1
INNER JOIN table2 t2 ON t1.H_ID = t2.H_ID
WHERE t1.Date = CURDATE( )
最佳答案
可能区分大小写。
或
table1有field2列吗?
如果不是/所以,根据你的问题,尝试这样:
SELECT t2.name
FROM table1 t1
INNER JOIN table2 t2 ON t1.h_id = t2.h_id
WHERE t1.Date = CURDATE()
<小时/>
另一种可能性是 where 子句,尝试如下:
SELECT t2.name
FROM table1 t1
INNER JOIN table2 t2 ON t1.h_id = t2.h_id
WHERE convert(varchar, t1.Date, 112) = convert(varchar, getdate(), 112)
<小时/>
最后一种可能性是 table1 和 table2 中没有任何 h_id 相等。
关于SQL查询: Join two tables with where clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9517915/