Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 311037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:53:18+00:00 2026-05-12T07:53:18+00:00

I need some help designing a friends system The mysql table: friends_ list –

  • 0

I need some help designing a friends system

The mysql table:
friends_ list
– auto_ id
– friend_ id
– user_ id
– approved_ status

Option 1 = Everytime a user adds a user there is 2 entries added to the DB, we then can get there friends like this

SELECT user_id FROM `friends_list` WHERE friend_id='$userId' and approved_status='yes'

Option 2 = We add 1 entry for every friend added and then get the friend list like this

SELECT friend_id AS FriendId FROM `friends_list` WHERE user_id='$userId' and approved_status='yes'
UNION
SELECT user_id as FriendId FROM `friends_list` WHERE friend_id='$userId' and approved_status='yes'

Of the 2 methods above for having friends on a site like myspace, facebook, all the other sites do, which of the 2 methods above would be best performance?

The 1st method doubles the ammount of rows, example a site with 2 million friend rows would only be 1 million rows the second method.

However does the union method mean there is 2 queries being made, so 2 queries on a million row table instead of 1?


UPDATE

I just ran some test on 60,000 friends and here are the results, and yes the tables are indexed.

Option 1 with 2 entries per friend;
.0007 seconds

Option 2 with 1 entry per friend using UNION to select
.3100 seconds

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:53:18+00:00Added an answer on May 12, 2026 at 7:53 am

    Option 1.

    Do as much work as possible on adding a friend. Adding someone is very rare compare to selecting all friends. Something probably done every time you render a page (on a social site).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 163k
  • Answers 163k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer MPI.NET's FAQ says On Unix, however, MPI.NET adapts itself to… May 12, 2026 at 12:14 pm
  • Editorial Team
    Editorial Team added an answer ANSI syntax (supported by SQL Server, Oracle, MySQL and PostgreSQL):… May 12, 2026 at 12:14 pm
  • Editorial Team
    Editorial Team added an answer \r\n characters will be converted to new line when you… May 12, 2026 at 12:14 pm

Related Questions

We are designing a client/server program and I need some help with a design
I have to make a graphical user interface application using the language of my
I'm in the process of writing a small overhead view RPG much in the
Hey everyone, great community you got here. I'm an Electrical Engineer doing some programming
Currently I am working with Java and its object oriented-design aspects (I also work

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.