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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:18:41+00:00 2026-05-26T09:18:41+00:00

The title pretty much says it all. I have users posting content, and I

  • 0

The title pretty much says it all. I have users posting content, and I would like to attach the user ID that is in the users table to the posts. Should I add a userid column in the posts table, should I join via the DB language, or should I use the scripting language to poll each table? If I should join, what kind of join should I do?

Sample content would look like this: “The teddy bears at my store are softer than the teddy goats, but the teddy goats are more lovable.” – Posted by James Teddyman at 3:36 PM.

  • 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-26T09:18:42+00:00Added an answer on May 26, 2026 at 9:18 am

    A very often-used concept in situation like this is by having a users table and a post table, linking them together with a unique identifier. This identifier can be anything – a serialized id, a user name, mail address, etc – as long as it’s unique. Linking is done using a foreign key constraint. Exactly how this is achieved in MySQL I do not know, but in Postgres it’s done like this:

    CREATE TABLE users (
      id serial PRIMARY KEY,
      name text
    );
    
    CREATE TABLE posts (
      content text,
      user_id integer REFERENCES users(id) NOT NULL
    );
    

    The tables are then merged using a join. This can be done in several ways, but here is a cross join after insertion of some values to play with:

    @> INSERT INTO users (name) VALUES ('James');
    @> INSERT INTO users (name) VALUES ('Jones');
    @> INSERT INTO posts (content, user_id) VALUES ('Hello from James.', 1);
    @> INSERT INTO posts (content, user_id) VALUES ('Greetings from Jones.', 2);
    @> SELECT U.id AS user_id, U.name, P.content \
       FROM users U, posts P \
       WHERE U.id = P.user_id;
    
     user_id | name  |        content
    ---------+-------+-----------------------
           1 | James | Hello from James.
           2 | Jones | Greetings from Jones.
    

    YMMV in MySQL, but I think the constructions above will work straight off.

    (edit: Added INSERTs for clarification)

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

Sidebar

Related Questions

The title pretty much says it all. I have a project that for political
The title pretty much says it all. If I have something like (from PHP
The title pretty much says it all. I have a regex that I need
Title pretty much says it all. Given a table like <table> <tr> <th>Header 1</td>
The title pretty much says it all. I would like to test e.g. UsersController::admin_index()
The Title pretty much says it all. I have an XML document that I
Pretty much what the title says really. We have some code that is .NET
The title, while long, pretty much says it all. What I have is a
The title pretty much says it all, but here's some background. We have a
The title pretty much says it. I have some methods that need to run

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.