15

I'm trying to understand how question's IDs are related to answer's IDs.

Here is the question:

https://stackoverflow.com/questions/48596476

We see, that it's ID is 48596476.

And here is the link to the second answer below this question:

https://stackoverflow.com/a/48597351/5587480

We can see, that all three IDs are different.

Instead, I expected something like this:

Question: https://stackoverflow.com/questions/48596476
Answer:           https://stackoverflow.com/a/48596476/5587480
                                                 |         |
                                           Question ID   Answer ID

So, on what logic these numbers are based on?

2
  • 13
    Note that there is no "question ID" or "answer ID", just a "post ID"
    – Floern
    Feb 3, 2018 at 14:52
  • 7
    Note that "link to the second answer" is stackoverflow.com/a/48597351 (note that there is only one id), the link you've provided in the post is "link to the second post as shared by me". Feb 3, 2018 at 16:22

2 Answers 2

35

5587480 is your user ID: https://stackoverflow.com/users/5587480 goes to your user profile. This is included to keep track of badges like Announcer.

It is possible to include both the question ID and the answer ID in an URL; you'll see that https://stackoverflow.com/a/48597351/ (a is short for answer, 48597351 is the answer ID) redirects to the following URL which includes both IDs: https://stackoverflow.com/questions/48596476/relationship-between-active-and-focused-states/48597351#48597351.

Answers and questions are both 'posts' and stored in the same database table. Therefore, they share a single 'sequence' which generates their IDs (in chronological order).

1
  • 11
    note that /q/ will also work, even if you feed it an answer id.
    – rene
    Feb 3, 2018 at 18:27
11

There is no direct relationship at all between the IDs (you can see parts of the Schema in the Data Dump or the Data Explorer).

Both Questions and Answers live in the same Table ("Posts") and differ in their PostTypeId, but share the same auto-increment ID Primary Key. Answers have a ParentId that points back at the question.

As for our URL, Glorfindel's answer already goes into specifics, but basically the ID of the question or any answer is enough for us to figure out which question page to fetch and render.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .