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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:47:15+00:00 2026-06-15T10:47:15+00:00

I asked a question earlier about extracting data from two table and got a

  • 0

I asked a question earlier about extracting data from two table and got a beautiful answer which worked perfectly by I asked a question earlier about extracting data from two table and got a beautiful answer which worked perfectly by Ollie Jones

Here is the new situation
I want to get a certain data from the first table by adding a WHERE but now it fails and it seems as if it should not

This query does just fine when performing this function

table 1       table 2

product 1     product 4
product 2     product 2
product 3
product 4


SELECT ifnull( b.number >0, 0 ) purchased
FROM 1androidProducts a
LEFT JOIN (
   SELECT count( * ) number, product
   FROM 1androidSales 
   WHERE udid = '' 
   GROUP BY product
) b 
ON a.appTitle = b.product
ORDER BY a.appTitle
LIMIT 0 , 30

yields this result

result 

0
1
0
1

in short
for every item in table 1 shows this

a 0 if the table-1-item does not appear in table two
–OR–
a 1 if table-1-item does show in table 2

Now when I add this line

SELECT ifnull( b.number >0, 0 ) purchased
FROM 1androidProducts a
WHERE a.accountID = 2        <<---------- I added this line 
LEFT JOIN (
   SELECT count( * ) number, product
   FROM 1androidSales 
   WHERE udid = ''
   AND accountID = 2          <<---------- I added this line
   GROUP BY product
) b 
ON a.appTitle = b.product
ORDER BY a.appTitle
LIMIT 0 , 30

It now gives an error

1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LEFT JOIN ( SELECT count( * ) number, product FROM 1androidSales ‘ at line 4

I simply want to get a subset of table 1 based on the accountID to compare against the second table.

so if I had this

         table 1            table 2

accountid =1  product 1     accountid =2  product 4
accountid =1  product 2     accountid =2  product 2
accountid =1  product 3     accountid =2  product 5
accountid =1  product 4
accountid =2  product 1     
accountid =2  product 2
accountid =2  product 3
accountid =2  product 4
accountid =2  product 5

would yield this result

result 

0
1
0
1
1

so the total number result records matches the amount of records in table one that meet the accountID value of 2

I thought this would be an easy change but it is messing me up big time

Thanks for your time

  • 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-15T10:47:16+00:00Added an answer on June 15, 2026 at 10:47 am

    I believe you have your first where clause in the wrong spot, put it after the join:

    SELECT ifnull( b.number >0, 0 ) purchased
    FROM 1androidProducts a
    LEFT JOIN (
       SELECT count( * ) number, product
       FROM 1androidSales 
       WHERE udid = ''
       AND accountID = 2 
       GROUP BY product
    ) b 
    ON a.appTitle = b.product
    WHERE a.accountID = 2 --Moved the first where clause
    ORDER BY a.appTitle
    LIMIT 0 , 30
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following up from an earlier question I asked about, I'm trying to read data
Earlier today I asked a question about configuring log4net from code and got an
I asked this question earlier about business logic and presentation logic, and it got
I asked an earlier question which was definitely helpful and let me know about
I asked a question earlier about which language to use for an AI prototype.
Ok, I asked a question earlier about Flex and ADO.NET Data Services but didn't
I asked a question earlier about extracting RAR archives in Java and someone pointed
I asked a question earlier about which method for saving would be better, I
Earlier today I asked this question which arose from A- My poor planning and
Earlier, I asked a question about getting windows active directory information from the user

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.