Command Only Returning One Row [SQL]

Hi,

I’m working on a project in SQl, and when I run certain commands, only one row of info is returned, instead of all of them. I can’t figure out why it can’t return everything.

Code:

SELECT
levels.id AS “ID”,
authors.name AS “Author”,
levels.name AS “Name”,
levels.theme as “Theme”,
levels.created AS “Date Uploaded”,
levels.difficulty AS “Difficulty”,
levels.tag AS “Tag”,
levels.shared AS “Times Shared”,
levels.liked AS “Stars”,
ROUND(((liked * 1.00) / (played * 1.00)) * 100, 2) AS “Star Rate”,
levels.played AS “Plays”, /* These Are The “Footsteps” */
SUM(tries_success + tries_taken) AS “Tries”,
levels.tries_success AS “Completions”,
levels.tries_taken AS “Deaths”,
levels.clear_rate AS “Clear Rate”
FROM levels, authors
WHERE levels.author_id = authors.id;

Thanks,
ProStar

I believe the problem is with using the SUM function. SUM is an aggregate function, and in this case is returning the SUM of the 2 columns inside your parenthesis added together. I think if you replace that line with (levels.tries_success + levels.tries_taken) AS "Tries", leaving out SUM, it will work as expected.
Hop this helps!

1 Like

This really helped, thanks!

2 Likes