Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3697378
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:51:10+00:00 2026-05-19T04:51:10+00:00

I have the below MySQL query, which should return the t1.username , t1.website ,

  • 0

I have the below MySQL query, which should return the t1.username, t1.website, in_count (WHERE t2.type = 'in'), out_count (WHERE t2.type = 'out') and WHERE the t1.website field is NOT EMPTY or NULL.

However its seemed to have malfunctioned (or I’m doing something wrong?), as it returns 1 result (via mysql_num_rows()) and when i print_r() (on the mysql_fetch_assoc()), the keys of the columns are their however all the values are empty/blank (see below).

The print_r() dump:

Array
(
    [username] => 
    [website] => 
    [in_count] => 
    [out_count] => 
)

The MySQL query:

SELECT t1.username,
       t1.website,
       SUM(IF(t2.type = 'in', 1, 0))  AS in_count,
       SUM(IF(t2.type = 'out', 1, 0)) AS out_count
FROM   users AS t1
       JOIN referrals AS t2
         ON t1.username = t2.author
WHERE  NOT Isnull(t1.website)
LIMIT  0, 10 

Hope all is clear, let me know if you need more information, appreciate all help. :B

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:51:10+00:00Added an answer on May 19, 2026 at 4:51 am

    Sounds like you might need a GROUP BY clause at the end? Perhaps

    GROUP BY t1.username, t1.website
    

    That way you’ll get all the in and out counts for a particular user on a particular web site.

    I was under the impression that with aggregate functions like SUM the query requires a GROUP BY clause… I’m surprised the server accepted your SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below query, which basically it retrieves the 5 top most books
I have a php page query mysql database, it will return about 20000 rows.
I have a multidimensional array which is created by a MySQL query which collects
Solution to original problem (below) may have been discovered. I commented out <identity> ...
I have the function below which I call very frequently in a loop. I
I have MySQL with below settings Server version: 5.0.77 MySQL client version: 5.0.41 Protocol
I have two mysql tables which both have a typeID in common. I am
I have created a subversion hook which does various things including sending out emails
I have the following MySQL query, and I'm trying to adjust it so it
I have a members only website in which the logged in users fill in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.