开发者

Sql, Advance Design help [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

SQL Statement to write table?

1) Consider the social network below. In this network nodes represent person and links represents friendships. For example, A and B are friends, and there is a link between A and B. You want to have a database to store your 开发者_如何学运维user profiles (id, fname, lname, email, gender, password-you can use node node names as ids), and users’s interests (a person can have multiple interests), and their friendship connections

so far i have only part of the sql statement done. i need help with the relationships

drop table users;
drop table intrest;
drop table friendships;

create table users(
id INT,
Fname char(15),
Lname char(15),
email char(20),
street char(15),
state char(2),
zip INT,
age INT,
gender char (2),
phone INT,
User_password char(15),
primary key (id)

create table Instrests(
id INT,
description char(30),
Primary key (id),
foreign key (users_id) 

create table friendships(


Btw there is a much better way to represent your data, upload a image (save you so much time if you screen dump the table struc and post on here) also I already have a post asking about relationships this was my output after some help.

Sql, Advance Design help [duplicate]

Notice the friendships between User and Friends and the sql syntax is like so:

select 
    u2.UserID,
    u2.FirstName,
    u2.SecondName,
    p.picturepath
from User u1 -- This gets me
join Friends f on u1.UserID = f.UserID -- This gets my friends
join User u2 on f.FriendID = u2.UserID -- This gets my friends info
join Pictures p on p.UserID = u2.UserID -- This gets my friends pics
where u1.UserID = 1  -- ...or whatever; don't actually hardcode "1"!

Now all you have to do is take this and apply it as such for your own method.


how about

friendships
------------
user_1_id
user_2_id
status
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜