开发者

my mysql result set is duplicating?why

开发者 https://www.devze.com 2023-01-22 00:20 出处:网络
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

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, fu开发者_JS百科ll_name, picture, date_join}


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.

0

精彩评论

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