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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:56:25+00:00 2026-06-03T04:56:25+00:00

I am writing an mysql query and getting error. Unknown column ‘dat’ in ‘field

  • 0

I am writing an mysql query and getting error.

“Unknown column ‘dat’ in ‘field list'”

This error occurred due to use alias in IF condition in mysql.

Here is mysql query :

SELECT 
    nCustomerID,
    dDateRegistered,
    (select count(nPlayerID) from credit_logs 
        where nPlayerID=nCustomerID) as total_clog,
    (select count(nPlayerID) FROM bl_transaction_history
        where nPlayerID=nCustomerID) as total_tran,
    (select count(nCustomerID) from customer_freeplays
        where nCustomerID=nCustomerID) as total_free,
    (select dDateAdded from bl_transaction_history
        where nPlayerID=nCustomerID) as dat,
    (select DATEDIFF(now(),dat)/30 ) as date_differece1,
    (select DATEDIFF(now(),dDateRegistered)/30 ) as date_difference2,
    IF (dat IS NOT NULL,(select DATEDIFF(now(),dat)/30 ),
        (select DATEDIFF(now(),dDateRegistered)/30 )) as date_difference
FROM bl_customers
WHERE nAccountStatus=1 
  and bDeleted=0 
having total_clog>0 
    or total_tran>0 
    or total_free>0

Any help would be appriciated.. 🙂

Thanks in advance.

  • 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-03T04:56:26+00:00Added an answer on June 3, 2026 at 4:56 am

    You can’t use alias columns, within your selection of other columns. You’ll need to copy the entire part of the query you’re aliasing, over and over again. ie. replace all occurrences of dat, after your initial declaration, with (select dDateAdded from bl_transaction_history where nPlayerID=nCustomerID)

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

Sidebar

Related Questions

I am getting this error when I try to query the database and write
I am writing a MySQL query that locks a table: LOCK TABLE table_1 WRITE
I am writing a nested MySQL query where a subquery returns more than one
I just finished writing this script and getting it to work but I need
Is there a shortcut for writing the following mySQL query? I am looking for
i am writing code of pagination & i got an error. this is my
I am having a problem writing a MySQL query to get data from 2
I am writing a very simple query, but I am getting duplicate values for
I am writing an advanced MySQL query that searches a database and retrieves user
I am writing in PHP a mySQL query. I would like to duplicate a

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.