我有3张桌子:
USERS(id, username, email, password)
QUESTIONS(id, uid, type, ques, date, time)
ANSWERS(id, a_uid, qid, reply, a_date, a_time)
我想从所有三个表中选择*
where $_SESSION[‘id’] = questions.uid
& users.id = questions.uid
& questions.id = answers.qid
我怎样才能实现这一目标?
答案 0 :(得分:0)
select *
from USERS
inner join QUESTIONS on users.id = questions.userid
inner join ANSWERS on questions.id = answers.qid
where questions.uid = $_SESSION['id'] ;
答案 1 :(得分:0)
您可以使用SQL joins来指定where子句。
select *
from USERS U
join QUESTIONS Q on U.id = Q.uid
join ANSWERS A on Q.id = A.qid
where $_SESSION['id'] = Q.uid ;