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

  • Home
  • SEARCH
  • 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 5929249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:23:50+00:00 2026-05-22T14:23:50+00:00

I have an invitations table in my database, which has got a from and

  • 0

I have an invitations table in my database, which has got a from and to columns, which are both foreign keys for the userId column in my users table.

For example, if User # 1 invited User # 2 to do something, then in the invitations table, from will be 1, and to will be 2.

I will use the to column in where statements, such as:

SELECT * FROM invitations WHERE `to` = $currentUserId

But the from column will never be used in WHERE statements.

From what I’ve read, you should only add an index on the columns which will be used in WHERE statements, however I’ve also read that you should always create Foreign keys.

Does it make sense for me to create an index on from just to add a foreign key?

  • 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-22T14:23:51+00:00Added an answer on May 22, 2026 at 2:23 pm

    In the case of foreign keys, you should add one depending on what you do with users.

    Internally, your fkeys will fire an action on any insert/update/delete of invitations, but also on any update/delete of users(id).

    The first of these will use the index on users(id) to check if the user exists.

    The other will essentially run a query that goes: do whatever you defined to do on update/delete from invitations where to/from = :id.

    So, if you change the id of users (very unlikely) you can make use of an index. And if you occasionally delete users (only slightly more likely), you can make use of the index.

    And as point out in the other answer, indexes are also useful for queries with an order by/limit clause.

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

Sidebar

Related Questions

In a View i have a table of users combining data from multiple database
I have three database tables: users emails invitations Emails are linked to users by
I have some view (Views 2 - list of invitations, table style) which uses
We have application named Milekeeper , which relays users to send invitations to race
I have a 'guests' table and 'invitations' table bound with many-to-one relationship in a
I have two table User userID username email 1 abc abc@abc.com 2 def def@def.com
I have a fairly complex page which contains an absolutely positioned table (as the
the users registered in a web site will have the possibility to send invitations
I got stuck on selecting fields from a table using SQL and PHP. I
I have a very simple use case. My app lets users send invitations to

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.