我有桌子:
|**USER**|
|--------|
| _id |
| name |
----------
下:
|**PHOTO**|
| _id |
| user | - integer FK
-----------
下:
|**RATING**|
| user | - integer FK
| photo | - integer FK
| seen |
------------
我所能做的就是提取数据:
|**USER**|**PHOTO**|**SEEN**|
|--------|---------|--------|
| 1 | 100 | 0 |
| 2 | 100 | 0 |
-----------------------------
我的问题:有没有办法提取:
|**USER**|**PHOTO**|**SEEN**|
|--------|---------|--------|
| name | 100 | 0 |
| name_2 | 100 | 0 |
-----------------------------
在此表中:
USER - 指用户 WHO 投票
照片 - 指用户投票的照片,但必须为_id = 2的用户PHOTO(例如)
SEEN - 仅指该行
想象一下功能:
function get_new_votes($myID){
....
}
任何帮助?
编辑:
例如:
USER
_id | name
----------------------
1 | random name
2 | different name
PHOTO
_id | user
-----------------
100 | 1
RATING
user | photo | seen
------------------------------
2 | 100 | 0
我想用上传用户_id = 1
的PHOTO提取所有记录different name | 100 | 0
答案 0 :(得分:1)
你可以在SQL中使用INNER JOIN
:
SELECT u.name, r.photo, r.seen
FROM rating AS r
INNER JOIN user AS u
ON r.user = u._id
INNER JOIN photo AS p
ON r.photo = p._id
WHERE p.user = <userId>