简体   繁体   中英

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

eg 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM