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

  • SEARCH
  • Home
  • 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 9205075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:51:59+00:00 2026-06-17T23:51:59+00:00

I have a query with a sub query to get the ranks of each

  • 0

I have a query with a sub query to get the ranks of each row based on tune_value. If I try to fetch the results I will get a general error from the PDOStatement::fetchAll();. The exectute of the prepare statement doesn’t seem to throw any errors.

I have the following query

SET @rank := 0;
SELECT * FROM 
(
  SELECT *,
         (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(tunes.creation_date)) as age,
         @rank := @rank + 1 as rank
  FROM tunes
  ORDER BY tune_value DESC
) as t
LEFT JOIN artists ON artists.id = t.artists_id
ORDER BY age

I prepare the statement using the following simplified php code.

   $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
   $stmt = $pdo->prepare($sql);
   $stmt->execute();
   $stmt->fetchAll(\PDO::FETCH_ASSOC);

Is it impossible to do this subquery with php? I was thinking about maybe making a view of the subquery.

EDIT: To clarify the query works fine in phpmyadmin

  • 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-06-17T23:52:01+00:00Added an answer on June 17, 2026 at 11:52 pm

    PDO doesn’t support multiple queries in one call.
    (Means PDO supports subqueries all right, it’s just doesn’t support multiple queries separated by a semicolon)
    You have to call them one by one.
    And to get errors from PDO, set this attribute

    $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    

    EDIT: This means the SET @rank := 0; is a separate query and should be queried in a separate call

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

Sidebar

Related Questions

I have a query that will return results from 2 tables into 1 using
i have a query that in a sub query calculates amount by dividing two
I have a query to select from another sub-query select. While the two queries
I have a sub query that returns one column, showing as GroupType, I then
I have a query with a sub query in the select that needs to
I have a query which is something like this SELECT t.category, tc.product, tc.sub-product, count(*)
I have query regarding specifying sub-parts of an element while defining a DTD for
I have this query with an sub query as clicks I want to do
I have a query in django that: gets the current category. based on that
So I have an nhibernate icriteria query that gets the list of results that

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.