0

I'm trying to get the following query both functional and controlled via inner joins rather than this format, as the way it is now will be slow once the db fills up

I've never been good with joins and this is the first time for me working with MS SQL rather than MySQL

help?

SELECT top 5
[user_friend].user_friendID as friendID,
[images].name as friendImage,
[user_bulletins].id as bulletin_id
[user_bulletins].title as bulletin_title
FROM
[user_bulletins], [user_friend], [images]
WHERE
[user_friend].user_id = [user_bulletins].user_id
AND
[images].user_id = [user_friend].user_friendID
AND
([user_friend].user_id = 64)
OR
([user_friend].user_friendID = 64)
AND
[images].display_photo = 1

2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by pty
0

may be typos here but you should try not to use square brackets in your sql; makes it much harder to read

also it is easier to join tables in the from clause rather than where, it makes more sense. I'd look in the documentation for more values but something like this may be easier :

SELECT top 5
uf.user_friendID as friendID,
i.name as friendImage,
ub.id as bulletin_id,
ub.title as bulletin_title
FROM
user_bulletins ub, 
join user_friend uf on ub.user_id = ub.user_id, 
join images i on ub.user_id = i.user_id
AND
(uf.user_id = 64 or uf.user_friendID = 64)
AND
i.display_photo = 1
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.