Hello Everyone,
I hope you enjoyed your weekend and are setting up for a great week.
I sit here thinking of how to design a buddy list in SQL for a mySQL
based implementation of an online community that has a concept of a
buddy list. I can't seem to think of an efficient way to manage the
status of buddies. Thank you in advance for any advice you may offer
to the below conundrum.
Basically, the buddy list should involve entities like this:
USER Table : Stores a unique ID and some general profile info
BUDDY Table: This is the table where I am having an issue. The highest
level concept is that two unique ID become matched up. Now in
practice, there are some states that need to be managed and I'd liek
to solicit any recommendations from you, if possible.
The states that need to be managed are:
user A REQUEST to Add user B to buddy list (Pending state)
user B DENIES adding user A (Need record of A Wanting to add B and a
record of B denying A)
OR
user A REQUEST to Add user B to buddy list (Pending state)
user B ACCEPTS adding user A (Need record of A Wanting to add B and a
record of B Adding A)
The ideal queries would be:
Who is a pending Buddy?
Who is my Buddy?
I was thinking of two tables:
TABLE BUDDYADD
USERIDONE
USERIDTWO
TABLE BUDDYDECLINE
USERIDONE
USERIDTWO
However, I can't think of an efficient way to search for Pending
items. In this case a pending item would be where BUDDYADD USERIDTWO
is ME AND I already didn't DENY this person. As you may guess it isn't
a 1:1 ration, so the query would look like: Who are all the users who
want to add me to their buddy list, so I can accept and deny them?
Another query of interest would be: Who are all my buddies? That is,
in TABLEADD Where USERIDONE is ME and USERIDTWO is BUDDY and USERIDONE
is BUDDY and USERIDTWO is ME. Seems not too efficient for me. Any
thoughts? Thank you for taking a look.
|
|
0
|
|
|
|
Reply
|
tatrader (3)
|
6/26/2007 3:57:32 AM |
|
>I hope you enjoyed your weekend and are setting up for a great week.
>
>I sit here thinking of how to design a buddy list in SQL for a mySQL
>based implementation of an online community that has a concept of a
>buddy list. I can't seem to think of an efficient way to manage the
>status of buddies. Thank you in advance for any advice you may offer
>to the below conundrum.
>
>Basically, the buddy list should involve entities like this:
>
>
>USER Table : Stores a unique ID and some general profile info
>
>BUDDY Table: This is the table where I am having an issue. The highest
>level concept is that two unique ID become matched up. Now in
>practice, there are some states that need to be managed and I'd liek
>to solicit any recommendations from you, if possible.
>
>The states that need to be managed are:
>user A REQUEST to Add user B to buddy list (Pending state)
>user B DENIES adding user A (Need record of A Wanting to add B and a
>record of B denying A)
>OR
>user A REQUEST to Add user B to buddy list (Pending state)
>user B ACCEPTS adding user A (Need record of A Wanting to add B and a
>record of B Adding A)
>
>The ideal queries would be:
>Who is a pending Buddy?
>Who is my Buddy?
I think you can do this with two tables: the User table and
the Buddy table. The Buddy table has three fields: UserID1, UserID2,
and Status. Status is an ENUM with these values:
PENDING User A has requested to add User B to his buddy list.
ACCEPTED Was PENDING, user B accepted.
DECLINED Was PENDING, user B declined.
Pending buddy: SELECT UserID1 WHERE UserID2 = '$me' and Status = 'PENDING';
My buddies: SELECT UserID2 WHERE UserID1 = '$me' and Status = 'ACCEPTED';
|
|
0
|
|
|
|
Reply
|
gordonb
|
6/26/2007 4:17:40 AM
|
|
On Jun 25, 9:17 pm, gordonb.qo...@burditt.org (Gordon Burditt) wrote:
> >I hope you enjoyed your weekend and are setting up for a great week.
>
> >I sit here thinking of how to design a buddy list in SQL for a mySQL
> >based implementation of an online community that has a concept of a
> >buddy list. I can't seem to think of an efficient way to manage the
> >status of buddies. Thank you in advance for any advice you may offer
> >to the below conundrum.
>
> >Basically, the buddy list should involve entities like this:
>
> >USER Table : Stores a unique ID and some general profile info
>
> >BUDDY Table: This is the table where I am having an issue. The highest
> >level concept is that two unique ID become matched up. Now in
> >practice, there are some states that need to be managed and I'd liek
> >to solicit any recommendations from you, if possible.
>
> >The states that need to be managed are:
> >user A REQUEST to Add user B to buddy list (Pending state)
> >user B DENIES adding user A (Need record of A Wanting to add B and a
> >record of B denying A)
> >OR
> >user A REQUEST to Add user B to buddy list (Pending state)
> >user B ACCEPTS adding user A (Need record of A Wanting to add B and a
> >record of B Adding A)
>
> >The ideal queries would be:
> >Who is a pending Buddy?
> >Who is my Buddy?
>
> I think you can do this with two tables: the User table and
> the Buddy table. The Buddy table has three fields: UserID1, UserID2,
> and Status. Status is an ENUM with these values:
>
> PENDING User A has requested to add User B to his buddy list.
> ACCEPTED Was PENDING, user B accepted.
> DECLINED Was PENDING, user B declined.
>
> Pending buddy: SELECT UserID1 WHERE UserID2 = '$me' and Status = 'PENDING';
> My buddies: SELECT UserID2 WHERE UserID1 = '$me' and Status = 'ACCEPTED';- Hide quoted text -
>
> - Show quoted text -
Gordon,
Thank you for the response, I like it. it is in my current design
plan, but one area I am struggling with is the buddy query might have
to go through with a union or two queries. Example:
My buddies: SELECT UserID2 WHERE UserID1 = '$me' and Status =
'ACCEPTED';
Case:
I request USER A
INSERT INTO BUDDIES VALUES(myId, USERA, PENDING);
USER B requests me
INSERT INTO BUDDIES VALUES(USERB, myId, PENDING);
Everyone likes one another so these tables get updated with ACCEPTED.
I'd need to union a query like:
SELECT UserID2 WHERE UserID1 = '$me' and Status = 'ACCEPTED';
UNION
SELECT UserID1 WHERE UserID2 = '$me' and Status = 'ACCEPTED';
Would this be the most efficient given circumstances of this matching
pairs? Appreciate it very much!
|
|
0
|
|
|
|
Reply
|
TATrader
|
6/26/2007 4:41:09 AM
|
|
>> >I sit here thinking of how to design a buddy list in SQL for a mySQL
>> >based implementation of an online community that has a concept of a
>> >buddy list. I can't seem to think of an efficient way to manage the
>> >status of buddies. Thank you in advance for any advice you may offer
>> >to the below conundrum.
>>
>> >Basically, the buddy list should involve entities like this:
>>
>> >USER Table : Stores a unique ID and some general profile info
>>
>> >BUDDY Table: This is the table where I am having an issue. The highest
>> >level concept is that two unique ID become matched up. Now in
>> >practice, there are some states that need to be managed and I'd liek
>> >to solicit any recommendations from you, if possible.
>>
>> >The states that need to be managed are:
>> >user A REQUEST to Add user B to buddy list (Pending state)
>> >user B DENIES adding user A (Need record of A Wanting to add B and a
>> >record of B denying A)
>> >OR
>> >user A REQUEST to Add user B to buddy list (Pending state)
>> >user B ACCEPTS adding user A (Need record of A Wanting to add B and a
>> >record of B Adding A)
>>
>> >The ideal queries would be:
>> >Who is a pending Buddy?
>> >Who is my Buddy?
>>
>> I think you can do this with two tables: the User table and
>> the Buddy table. The Buddy table has three fields: UserID1, UserID2,
>> and Status. Status is an ENUM with these values:
>>
>> PENDING User A has requested to add User B to his buddy list.
>> ACCEPTED Was PENDING, user B accepted.
>> DECLINED Was PENDING, user B declined.
>>
>> Pending buddy: SELECT UserID1 WHERE UserID2 = '$me' and Status = 'PENDING';
>> My buddies: SELECT UserID2 WHERE UserID1 = '$me' and Status =
>'ACCEPTED';- Hide quoted text -
>>
>> - Show quoted text -
>
>Gordon,
>
>Thank you for the response, I like it. it is in my current design
>plan, but one area I am struggling with is the buddy query might have
>to go through with a union or two queries. Example:
In my view, "A is a buddy of B" and "B is a buddy of A" are completely
separate. Thinking of it another way, "A is a stalker of B" doesn't
mean "B is a stalker of A", although I suppose you can have two
people stalk each other. Worse, "A is an uncle of B" doesn't mean
"B is an uncle of A", although if you watch the Jerry Springer show
long enough, you'll find an example of mutual uncleship.
There's two buddy lists, those *I* invited and those who invited
*me*. Say, if *I* invited *them*, they can look at *my* private
pages for buddies only. If *they* invited *me*, I can look at
*their* private pages for buddies only. Those lists might be mostly
identical for most people. Now, it's quite possible that my mother
insists that I invite her as a buddy so she can look at my pages,
otherwise she won't let me sign up, but she doesn't want me looking
at nude pictures (or lack thereof) of *her* on her pages. That's
a reason for non-mutual buddyship.
>My buddies: SELECT UserID2 WHERE UserID1 = '$me' and Status =
>'ACCEPTED';
>Case:
>I request USER A
>INSERT INTO BUDDIES VALUES(myId, USERA, PENDING);
>
>USER B requests me
>INSERT INTO BUDDIES VALUES(USERB, myId, PENDING);
>
>Everyone likes one another so these tables get updated with ACCEPTED.
>I'd need to union a query like:
>
>SELECT UserID2 WHERE UserID1 = '$me' and Status = 'ACCEPTED';
>UNION
>SELECT UserID1 WHERE UserID2 = '$me' and Status = 'ACCEPTED';
>
>Would this be the most efficient given circumstances of this matching
>pairs? Appreciate it very much!
You might manage this based on what happens when one buddy relationship
is proposed and the other accepts. If buddyship must be mutual,
then you could create "ACCEPTED" records that go both ways (one
already exists as pending). That eliminates the union, but costs
twice as much in table entries and some queries in establishing
buddyship. It also means that things *could* get screwed up and
you accidentally have one-way buddy relationships that stick around.
I recommend the use of transactions so changing one status to
ACCEPTED and inserting the record going the other way either both
happen or both don't.
I presume generating buddy lists is frequent and establishing
buddyship with another person is much less common.
Other things to think about:
If one person proposes buddyship and the other person declines, can
the proposal be done again? How soon? Do you then get rid of the
DECLINED record once the proposing person is notified of the decline,
or after a specific time (in which case you need a timestamp in the
record). If one person proposes buddyship and the other person
accepts, can either person change his mind later?
|
|
0
|
|
|
|
Reply
|
gordonb
|
6/27/2007 12:15:16 AM
|
|
Thank you very much for the help and discussion, in fact those extra
cases need to be accounted for. My solution was to duplicate entries
like you recommended, with a status enum.
USERA USERB COL1ADDCOL2
USERB USERA COL2ADDCOL1
|
|
0
|
|
|
|
Reply
|
TATrader
|
6/27/2007 5:03:13 AM
|
|
|
4 Replies
114 Views
(page loaded in 0.109 seconds)
Similiar Articles: Answer: Excel Export, Query Defs, SQL IN criteria - comp.databases ...... Post Question | Groups ... table. jtRegion/jtCounty are only linked to the main table in the query, not the db design. How best to detect duplicate values in a column? - comp.databases ...Note: You didn't even attempt to answer my original question: Which type of SQL query is best ... You have no idea about database design, program design - OR DEVELOPMENT. Access 2007 autofill DLookup - comp.databases.ms-access... data entry forms, you have to worry about the database design. ... The JoinSiteGenus table allows you to ask questions ... Globally replace table name in access queries - comp ... A2010 Query property sheet - comp.databases.ms-access> Perhaps you can answer a quick question. When Access starts one can select a "blank database" or "blank web ... In Query Design View, the default Field Properties (General ... Establish When Multiple Fields Are True/False -1/0 Yes/No From A ...I relaise this can be done by using a Union Query ... > As you've discovered, this is not the ideal design for the question ... Adding simple database, excel export, and reports ... FMP basic questions....help appreciated - comp.databases.filemaker ...I work with an application that queries an Access database, so that ... this the correct way of establishing the design ... FMP basic questions....help appreciated - comp ... How many of one string in another - comp.databases.mysql ...I have a column in a database. Let's say for this question it looks like ... Please show an example of a query that ... For the record, I did not design this database ... Oracle SQL bug in 9.2.0.8 - comp.databases.oracle.server ...Same happens with the inner dual query. Which ... happens when you let script-kiddies create/design database ... at replies in context of > the original question is an ... A2010: gridlines in form design - comp.databases.ms-access ...A2010 Query property sheet - comp.databases.ms-access Access 2010 table design questions I have some ... ... A2010: gridlines in form design DataBase - DataBase ... DS 5.2 cert7.db - comp.unix.solaris... Post Question | Groups ... MP and announced that they would use it to design the ... its not what I expected: 550 5.1.2 ... access_db query ... Business Questions for Database Design, Part TwoForming Queries Part 1: Design; Forming Queries Part 2: Query Basics; Forming Queries ... Business Questions for Database Design, Part Two. Last updated Jan 14, 2011. What is a database query - The Q&A wikiIn later tutorials we'll examine the Design view which facilitates ... A database "query" is basically a "question" that you ask the database. The results of the query is ... 7/20/2012 8:05:35 AM
|