开发者

mysql query for the following problem? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 9 years ago.

Improve this question

I have three tables say 'user', 'user_resources' and 'desktop_resources'.

'user' contains - emp_id,name and other attributes

'user_resources' - emp_id and desktop_id foreign key relation

'desktop_re开发者_开发技巧sources' - desktop_id and other attributes

Now i want a sql query from where i can get a table which shows me name from 'user' table and 'desktop_resources' attributes only where "emp_id=d_id"

how to go about it??


I don't see d_id column there, but if you think so, it would look like this:

SELECT name, desktop_resources.*
FROM desktop JOIN user_resources USING (desktop_id) JOIN user USING (emp_id)


This is a straightforward series of joins:

select u.name, dr.*
from user u
join user_resources ur on ur.emp_id = u.emp_id
join desktop_resources dr on dr.desktop_id = ur.desktop_id
where u.emp_id = $d_id


Finally found this query useful:

SELECT name, desktop.*
FROM desktop
NATURAL JOIN (
user
JOIN user_resource ON user.emp_id = user_resource.emp_id
)

I am sure there may be other ambiguous queries for this..if u have got a better query..please put it in comments...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜