如何从匹配多个过滤器的表中获取数据?

时间:2012-04-17 10:43:09

标签: php mysql

我有两个不同的表:tbl_records,tbl_users

我想从tbl_records中获取所有数据,这些数据由f_name ='Kr'发布,并且今天插入(记录日期)。

Image of database structure

2 个答案:

答案 0 :(得分:1)

这将返回tbl_records中f_name为'Kr'的用户的所有列,其中date_of_record为今天午夜或晚于。午夜。

SELECT r.* FROM tbl_records r
INNER JOIN tbl_users u ON r.user_id = u.user_id
WHERE r.date_of_record >= DATE(NOW()) AND u.f_name LIKE 'Kr'

虽然通常最好指定所需的确切列,以防以后更改表定义:

SELECT r.user_id, r.status, r.date_of_record FROM tbl_records r
INNER JOIN tbl_users u ON r.user_id = u.user_id
WHERE r.date_of_record >= DATE(NOW()) AND u.f_name LIKE 'Kr'

答案 1 :(得分:0)

试试这个,

SELECT * FROM tbl_records AS tr JOIN tbl_users AS tu ON ( tr.user_id = tu.user_id ) AND tr.date_of_record = DATE(NOW()) AND tu.f_name = 'kr'