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 6172491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:24:12+00:00 2026-05-23T23:24:12+00:00

I have a table called foo with columns like the following: id usedId (id

  • 0

I have a table called foo with columns like the following:

id 
usedId (id of the person who posted this foo)
title
postedDate

What I want to do, is add another column called position, which will record how many foos a user has posted. E.g, his first posted foo will have the position of 1, 2nd will have 2, 100th will have 100, and so on. But this position is specific to the userId only.

Is there a way to add such a column to mysql, or I must calculate the position programatically?

  • 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-23T23:24:14+00:00Added an answer on May 23, 2026 at 11:24 pm

    Calculating it pragmatically is the best way to keep your database normalised, since you shouldn’t have any data stored which can be calculated later. You should just order by the postedDate, and count which position you’re on with each iteration.

    However, if you were going to go ahead with this, you’d have to count the number of rows that the user already has, using a sub-query. So this would be part of your insert query:

    [..], position = (SELECT COUNT(*) + 1 FROM foo WHERE userId = $userId), [..]
    

    The sub-query would just return the number of rows already in the table for the user with the ID $userId, and increment it by one.

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

Sidebar

Related Questions

I have a table called Foo and I have two columns: Lorem and Ipsum,
All, I have the following table called Foo which is the output of a
Let's say I have a mysql table, called foo with a foreign key option_id
I have a table called 'MyTable' that looks like: ID | Item | Type
I have a table called sellerparams with a number of columns, one of them
I have a table called 'main_table' with 3 columns : 'player', 'points' and 'drop_date'
I have an interesting question: I have a table with trigger names, called Foo
I have a MySQL table called Cars . The Cars table has three columns:
I am running PostgreSQL. I have a table called foo .Its content are: city|number
I have a Table with a NUMERIC(38,0) field called FOO . In an UPDATE

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.