Explain PostTypeId (Tutorial)

1

Please login or register to vote for this query.

(click on this box to dismiss)

Computational Science

Q&A for scientists using computers to solve scientific problems

-- The first query here (commented out; uncomment it and comment out from
-- "SELECT DISTINCT" to run it) just returns post IDs with their numerical
-- post types.  Not very exciting, is it?

-- Run this query, what does PostTypeId mean? It's a number!
-- SELECT Top 100 Title, Id, PostTypeId
-- FROM Posts
-- ORDER BY Id DESC

-- Now try this instead:

SELECT DISTINCT p.PostTypeId, pt.Name
FROM Posts p
JOIN PostTypes pt ON p.PostTypeId = pt.Id
ORDER BY p.PostTypeId ASC

-- This can be seen much easier if you click on the "i" icon
-- next to the PostTypes table in the right-hand table list.

-- Query written by jmac

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results