sql - How to query for both posts and post upvotes in MySQL?

I am attempting to model post upvotes and posts in MySQL. Currently I have an elements table for posts and a likes table for upvotes, structured as follows.

likes (id, elementID, googleID)

elements (id, googleID, title, body, type)

I have a URL route that will either return the most recent posts, or the posts with the most upvotes depending on a parameter. I want to query for a set of posts, each listing how many upvotes they have. The website won't display who upvoted, but the database should keep track of this to prevent multiple upvotes.

The website won't display who upvoted, but the database should keep
track of this to prevent multiple upvotes

You can create a UNIQUE CONSTRAINT in your LIKES table, for elementID and googleID columns. This will make sure that a googleID can only like one elementID. Otherwise, it will throw a unique constraint violation.

With that, when a user is upvoting a post, you can check in the database first if the user has already an existing record in the LIKES table before inserting one.