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 9093349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:04:38+00:00 2026-06-16T23:04:38+00:00

I have following two query both are same but differs only in structure. First

  • 0

I have following two query both are same but differs only in structure.

First query:

SELECT DISTINCT 
    u.username, r.value, u.amount AS `amount`
FROM 
    Daily_Balance_Updates u
INNER JOIN 
    Role r ON u.role_id = r.id
WHERE 
    u.updated_at = (SELECT MAX(inner_u.updated_at)
                    FROM Daily_Balance_Updates AS inner_u
                    WHERE inner_u.username = u.username
                       && amount > 0
                       && UNIX_TIMESTAMP( inner_u.updated_at ) < UNIX_TIMESTAMP( '2013-1-3 23:59:59' )
)
ORDER BY 
    r.value, UNIX_TIMESTAMP( u.updated_at ) DESC

Works fine in Phpmyadmin

Second query

And same query when I use in Java I declare as follow:

query="SELECT DISTINCT u.username, r.value, u.amount AS `amount' FROM Daily_Balance_Updates     u INNER JOIN Role r ON u.role_id = r.id WHERE u.updated_at = ("
+ "SELECT MAX(inner_u.updated_at) FROM Daily_Balance_Updates AS inner_u WHERE inner_u.username = u.username && amount > 0 && UNIX_TIMESTAMP( inner_u.updated_at ) < UNIX_TIMESTAMP('" +date+" 23:59:59' )) ORDER BY r.value DESC,UNIX_TIMESTAMP( u.updated_at )"

but when I execute it it gives error in both phpmyadmin and java

ERROR

Unknown table ‘u’ in field list

My log:

12:23:17,963 INFO  [STDOUT] 2013-01-07 12:23:17,962 ERROR 
    com.walletplus.report.dao.ReportDaoMysql -  Thread #98  - 
    StatementCallback; bad SQL grammar 
        [SELECT DISTINCT u.username, r.value, u.amount AS `amount' FROM 
            Daily_Balance_Updates u INNER JOIN Role r ON u.role_id = r.id   
            WHERE u.updated_at = (SELECT MAX(inner_u.updated_at) FROM
            Daily_Balance_Updates AS inner_u WHERE inner_u.username = u.username    
            && amount > 0 && UNIX_TIMESTAMP( inner_u.updated_at ) < 
            UNIX_TIMESTAMP('2013-01-01 23:59:59' )) ORDER BY r.value DESC]; 
            nested exception is java.sql.SQLException: Unknown table 'u' in field list

Question:

What is wrong with query? It seems all right.

  • 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-16T23:04:40+00:00Added an answer on June 16, 2026 at 11:04 pm

    You have two differences in those two queries

    • `amount` vs `amount’, both quotes must be backticks.
      I guess, that’s the reason, why FROM Daily_Balance_Updates u isn’t recognized, and you get the misleading error message.
    • order by ... desc, ... vs order by ..., ... desc

    Another point, if you have a user_id in addition to username, comparing the user_ids in the where clause would be faster.

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

Sidebar

Related Questions

I have two tables that I am joining with the following query... select *
I have the following two queries which I want to get in one query.
I have the following query where I combine two fields from two tables: <cfquery
i have the following query to list the employees of two table. i need
I have written a SQL query in following two ways, as the underlying data
if I have a table like the following, how could I only select out
i have following two queries, one is create procedure query and other is the
I want a mysql query for following scenario I have following database structure 1]
I have following two arrays. I want the difference between these two arrays. That
How to wrap one div around another? I have following two div ids: #course

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.