我有一个买卖东西的网站。
在一个页面中,我需要获得有关用户的所有信息...他的销售,购买,他的名字,他的照片......
我做的是:
SELECT id, nome FROM users WHERE user=?
SELECT count(id) as num FROM sells WHERE user=?
SELECT count(id) as num FROM buy WHERE user=?
SELECT count(user) as num FROM questions WHERE user=?
SELECT img FROM picture WHERE user=?
我可以只使用一个选项来获取所有这些信息吗? (任何人都可以给我一个例子)它会更快/更好还是我应该继续每桌选择一个?
答案 0 :(得分:0)
尝试这样:
SELECT u.id,
u.name,
count(s.id) sells_count,
count(b.id) buy_count,
count(q.user) question_count,
p.img
FROM users u, sells s, buy b, questions q, picture p
WHERE u.user=?
and s.user = u.user
and b.user = u.user
and q.user = u.user
and p.user = u.user