Gaming need mysql help

MFDC12

Well-Known Member
OP
Member
Joined
Oct 12, 2007
Messages
822
Trophies
1
Age
32
XP
938
Country
United States
I need some help with a mysql query but I can't figure it out for the life of me.
I need to count the amount of people who were referred to the site by another member, as long as they have one post. This would not be a problem for me if they were not in two different tables and having needed a count (which I am having trouble with).

Here are the two queries I want to join:
SELECT DISTINCT u.ref_by, u.id FROM users AS u WHERE u.status = 'confirmed' GROUP BY u.ref_by ORDER BY refs DESC;
SELECT COUNT(*) FROM history WHERE userid = u.id AND posts > 1";

Problems:
I dont know how to count the total amount.
The part in bold, I am not sure how to do that. I have tried unions and all types of joins, but I can't seem to get this to be used from the first query (always results in something life "u.id unknown in where clause")

Any help is appreciated, this has given me a headache for about 5 hours now and I give up.
Thanks!
 

Jiggah

Well-Known Member
Member
Joined
Nov 9, 2002
Messages
1,223
Trophies
0
Website
Visit site
XP
279
Country
United States
Why wouldn't you use the first select statement to find the people with one post?


For example,

SELECT DISTINCT u.ref_by, u.id FROM users as u, history WHERE u.id = userid and u.status = "confirmed" and post >= 1;

You can then use that select statement within a count:

SELECT COUNT(*) FROM (SELECT DISTINCT u.ref_by, u.id FROM users as u, history WHERE u.id = userid and u.status = "confirmed" and post >= 1) as CONUSER;


The reason why your second query is messing up is because for that SELECT statement you're only referencing the "history" table. It doesn't know what u.id is.
 

MFDC12

Well-Known Member
OP
Member
Joined
Oct 12, 2007
Messages
822
Trophies
1
Age
32
XP
938
Country
United States
Jiggah said:
Why wouldn't you use the first select statement to find the people with one post?


For example,

SELECT DISTINCT u.ref_by, u.id FROM users as u, history WHERE u.id = userid and u.status = "confirmed" and post >= 1;

You can then use that select statement within a count:

SELECT COUNT(*) FROM (SELECT DISTINCT u.ref_by, u.id FROM users as u, history WHERE u.id = userid and u.status = "confirmed" and post >= 1) as CONUSER;


The reason why your second query is messing up is because for that SELECT statement you're only referencing the "history" table. It doesn't know what u.id is.

You got exactly what I'm trying to do except for one thing - i need it so it groups it by ref_by, rather than a total number.

Thanks for helping so far!
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • light27 @ light27:
    fun fact
  • light27 @ light27:
    the first time i ever played on a wii u EVER was when I was getting my ear tubes removed
  • light27 @ light27:
    i was playing wii party
  • light27 @ light27:
    u*
  • light27 @ light27:
    but i only got to play for like
  • light27 @ light27:
    3 seconds
  • light27 @ light27:
    younger me would've never thought that I would have a wii u now
  • Xdqwerty @ Xdqwerty:
    @light27, i wanted a Wii u as a kid when i watched a Mario kart 8 commercial on tv
  • Psionic Roshambo @ Psionic Roshambo:
    I had a Wii-U it sucked lol
  • Psionic Roshambo @ Psionic Roshambo:
    Even hacked it sucked lol
  • The Real Jdbye @ The Real Jdbye:
    nah the Wii U wasn't bad
    +1
  • The Real Jdbye @ The Real Jdbye:
    the hardware is good
  • Psionic Roshambo @ Psionic Roshambo:
    The controller sucked
  • The Real Jdbye @ The Real Jdbye:
    it has good games, just not enough of them
    +2
  • ColdBlitz @ ColdBlitz:
    the indie games on wii u were amazing though
  • ColdBlitz @ ColdBlitz:
    and also some of nintendo's first party games
  • ColdBlitz @ ColdBlitz:
    some of the best selling games on the switch are wii u ports (that are priced way too high
    like come on 60 for a game thats a decade old??)
    +1
  • Xdqwerty @ Xdqwerty:
    @ColdBlitz, i forgot breath of the wild released for the Wii u
  • The Real Jdbye @ The Real Jdbye:
    $60 for a game that's a decade old might be unheard of on PC but actually is not uncommon on consoles
    +1
  • The Real Jdbye @ The Real Jdbye:
    especially Nintendo because they only ever lower the price of games when they do a greatest hits/platinum hits/players choice re-release
  • Xdqwerty @ Xdqwerty:
    @The Real Jdbye, and the HD collections released for 7th gen consoles too
  • The Real Jdbye @ The Real Jdbye:
    but they don't seem to have done any of those for the switch yet and maybe never will
  • ColdBlitz @ ColdBlitz:
    I think we all forgot breath of the wild released for the wii u tbh
    +1
  • Xdqwerty @ Xdqwerty:
    @The Real Jdbye, tbh the HD collections are more justified since they include more than just 1 game per copy
    Xdqwerty @ Xdqwerty: @The Real Jdbye, tbh the HD collections are more justified since they include more than just 1...