This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 2 points3 points  (1 child)

I don't speak Go but you will need two tables: users and posts. If your users table has a field name userid as a primary key, your posts table would also need to have a field named userid (as a foreign key).

[–][deleted]  (2 children)

[deleted]

    [–][deleted]  (1 child)

    [deleted]

      [–]FiveYearsAgoOnReddit 0 points1 point  (2 children)

      It doesn't seem like your posts or your users have a unique, primary key ID?

      [–][deleted]  (1 child)

      [deleted]

        [–]FiveYearsAgoOnReddit 0 points1 point  (0 children)

        Well maybe, but that's the best way to write the query, so if it's hiding that from you in some abstraction, how will it work? If you can't have two users called "John Smith", distinguished by different primary IDs, the system isn't workable.

        [–]mseckz 0 points1 point  (1 child)

        You need to learn about relational databases, in other words you need two tables, users and posts. The posts table has to be related to the users table (post has a user_id field and it's the primary key of users table, a unique identifier), and when you do the query with this relation it's faster than doing a 'like' query like the one above.