开发者

MySQL query design question

If a user has there deletion field with a value of 1 how can I igonre all there comments and there main comments that have children under them from other users? How would my query look like.

Here is my MySQL tables

CREATE 开发者_运维问答TABLE articles_comments (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
parent_comment_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
article_id INT UNSIGNED NOT NULL,
comment TEXT NOT NULL,
date_created DATETIME NOT NULL,
PRIMARY KEY (id),
KEY user_id (user_id),
KEY article_id (article_id)
);

CREATE TABLE users (
user_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(255) NULL,
password CHAR(128) NOT NULL,
active CHAR(32),
deletion TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (user_id),
UNIQUE KEY (username)
);


Assuming your original query was

Select ---columns--- From ---tables--- Where ---clauses---

and ---tables--- included joining the root_comment to the users table

e.g. articles_comments root_comment Join Users root_user ON (root_comment.user_id = root_user.user_id)

then add a second condition to the ON clause

articles_comments root_comment Join Users root_user ON (root_comment.user_id = root_user.user_id and root_user.deletion != 1)

If this doesn't do what you want, could you clarify your question?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜