If I have a users table and a question table, where one user can have multiple questions, can I return, for example,
bob | 10 questions
sam | 2 questions
with one query?
Using php with pdo for what it’s worth.
users table
userID
name
etc.
questions table
questionID
userID
question
flagged
answered
etc.
I want some fields from the users table and a count of the associated questions on the same row. if it can’t be done I’ll just use separate queries but I just thought I’d ask for the sake of having tidier code
Something like this:
If you only want some columns from the users table, replace
u.*with the list of columns you care about.