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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:29:44+00:00 2026-05-26T02:29:44+00:00

This query is working perfectly on my dev machine, a PC with mysql 5.1.53

  • 0

This query is working perfectly on my dev machine, a PC with mysql 5.1.53

 SELECT DISTINCT * 
 FROM   posts P1
 WHERE  user_id IN (2,1000001) AND NOT track_id = 34 AND
        (SELECT COUNT(*) FROM posts P2 
            WHERE P2.user_id = P1.user_id AND P2.id > P1.id AND P2.track_id <> 34)
         <= 1
 GROUP BY 
        track_id 
 ORDER BY 
        id desc LIMIT 5

when i run the very same piece of code in the same database on my live server (debian, mysql 5.1.39), i get this error:

Unknown column 'P1.user_id' in 'where clause': 

How could this be? Any ideas?

Result of show create table posts on the server

CREATE TABLE `posts` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`track_id` int(11) unsigned DEFAULT '0',
`tag_id` int(11) unsigned DEFAULT NULL,
`user_id` int(11) DEFAULT '0',
`comment` tinytext,
`created_at` datetime DEFAULT NULL,
`commentcount` tinyint(11) unsigned DEFAULT '0',
PRIMARY KEY (`id`),
KEY `track_id` (`track_id`),
KEY `tag_id` (`tag_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM AUTO_INCREMENT=484 DEFAULT CHARSET=utf8 |
  • 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-26T02:29:45+00:00Added an answer on May 26, 2026 at 2:29 am

    As a lot of comments suggested, it was an issue with case sensitivity. In the SQL query on the server, the alias of posts was set to “p1”, but the subselect was looking for “P1”. Mistake.

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

Sidebar

Related Questions

Why this query doesn’t working: SELECT name FROM ( SELECT name FROM table1 UNION
In a SQL Server 2005 database I'm working on this query: select * from
I have this query working but it is not returning back exactly what I
how come this isn't working: $url = http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20xpath%3D%22%2F%2Fmeta%22%20and%20url%3D%22http://www.cnn.com%22&format=xml&diagnostics=false; $xml = (simplexml_load_file($url)) I get multiple
I'm working with a MySQL query that writes into an outfile. I run this
This is assignment so not looking for anything perfectly safe and secure, just working.I
I have this query SELECT t1.Trans_ID FROM (SELECT * FROM Prune WHERE [Name]=I1) AS
This code is working perfectly: $(document).ready(function() { $(#submit).click(function(){ $(#output).load(extract.php, {query: $(#input).val()} ); }); });
Whats this?? my query is: Doctrine_Query::create() ->select('rec.*') ->from('Records rec') ->execute(); Records table contains more
I am using this query: SELECT * from likes GROUP BY url ORDER BY

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.