0

I want to implement connection as friends of friends using MySQL

1 Answer 1

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),
);

Was that really so hard?

Sign up to request clarification or add additional context in comments.

2 Comments

maybe he meant how to traverse such tables? running DFS on mySql can be tricky
add engine=innodb (now default in 5.5) and drop key lookup(user_a_id) and you'll be well sorted !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.