Jump to content

[SOLVED] Select Query with 2 Tables joined doing a function of count confusing


sspoke

Recommended Posts

Hello,

 

I want to do what title says

 

anyways Here is the layout

 

Table1->gametypes->Columns->   id(primary,auto ++) and gamename(text)

Table2->matches->Columns->   id(primary,auto++) and gameid(int) which is the ID that matches Table1 id and a bunch of other columns which I don't have to list

 

everytime someone makes a match from my program it would insert query into Table2

 

but if someone wants to lets say see the amount of rooms made per each catagory in 1 return of gametypes how would I do that in 1 Query  I could do it in 2 queries but I really need this in 1 query..

 

this is what I got

 

SELECT * FROM gametypes INNER JOIN (SELECT Count(gameid) FROM matches WHERE gametypes.id = matches.gameid)

 

I missed the ON operator somewhere but ya lol confusing..

 

It gives a sql error  Every dervied table must have its own alias.. 

 

Thanks for any help

Link to comment
Share on other sites

but if someone wants to lets say see the amount of rooms made per each catagory in 1 return of gametypes how would I do that in 1 Query  I could do it in 2 queries but I really need this in 1 query..

 

If this is not what you're looking for, explain what a "category" and a "room" is. The description of the tables don't give much indication as to what you mean by the two.

 

SELECT
g.*, COUNT(m.gameid) AS num
FROM
gametypes AS g
LEFT JOIN
matches AS m
ON
g.id = m.gameid
GROUP BY
g.id

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.