我想使用MySQL实现连接作为朋友的朋友
答案 0 :(得分:4)
CREATE TABLE user (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
email VARCHAR(60) NOT NULL,
....
PRIMARY KEY (id)
);
CREATE TABLE friendof (
user_a_id MEDIUMINT NOT NULL,
user_b_id MEDIUMINT NOT NULL,
PRIMARY KEY(user_a_id, user_b_id),
FOREIGN KEY(user_a_id) REFERENCES user(id),
FOREIGN KEY(user_b_id) REFERENCES user(id),
KEY reverseLookup (user_b_id),
KEY lookup (user_a_id),
);
真的那么难吗?