1.建立用户信息表
create table userinfo(id int(4) not null primary key, name varchar(20) not null unique key)engine=innodb default charset=utf8;
2.建立好友关系表
create table friend(uid int(4) not null, foreign key(uid) references userinfo(id),fid int(4) not null, foreign key(fid) references userinfo(id),unique key(uid,fid))engine=innodb default charset=utf8;
3.追加测试数据(满足uid<fid条件)
insert userinfo values(1111---9999,'namea---namei’);
insert friend values(1111,4444---6666);
insert friend values(5555,6666---9999);
4.查询好友(5555的好友)
select * from friend where uid=5555 or fid=5555;
+-------+------+
| uid | fid |
+-------+------+
| 1111 | 5555 |
| 5555 | 6666 |
| 5555 | 7777 |
| 5555 | 8888 |
| 5555 | 9999 |
+-------+--------+
5.问