views:

40

answers:

1

im doing this query on mysql, but its giving me duplicate results sets:

this is my query:

SELECT u.username, u.picture, m.id, m.user_note, m.reply_id, m.reply_name, m.dt, m.votes_up
FROM user u, notes m
WHERE m.topic_id =14
ORDER BY m.dt DESC

i dont understand why its doing it? please help :))

EDIT: table schema

notes{id, user_id, topic_id, user_note, reply_id, reply_name, votes_up, dt}
user {user_id, username, password, email, full_name, picture, date_join}
+3  A: 

You have no join condition on your where clause. Its create a Cartesian product of your results I would guess.


So you have two tables when you select from two tables it gives you the Cartesian Product of the results sets or all the rows in A X all the rows in B. What you need to do is link the two tables together ie to relate them. select * from User as U,Notes as N where U.ID = N.UserID Then add your other constraints.

rerun
thanks, but i dont understand lool :((
getaway
but i don't want to select only one user, i want all the users notes. i still dont get whatyou mean im still a newbie to this
getaway
only if i link it with the topics table, i.e t.topic_id =n.topic_id, but that would be mkaing the database engine work harder, when i already have topic_id value that i needed :)) if you get what i mean
getaway
you won't get only one user, you'll end up with all notes and their user selected on one line per user/note combination. to get only one user you'd have to do something like u.id = 1.
nathan gonzalez
You want all the user information for every user linked to topicid 14 is that right?
rerun
oh my god im so stupid, yeh thats true, sorry sorry, yeh fixed it, i need to wake up and smell the coffee sireous? wow thanks you guys +upvote for me
getaway
Thats why you ask questions
rerun
@rerun is that a good thing or bad thing lol
getaway