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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:45:45+00:00 2026-06-07T21:45:45+00:00

I had a mysql query : Select count(*) as cnt from page06 where dl

  • 0

I had a mysql query :

Select count(*) as cnt from  page06 where dl = 1 and TYPE = 'mempage' union 
Select count(*) as cnt from  page06 where err = 1 and TYPE = 'mempage' union  
Select count(*) as cnt from  page06 where dl = 1 and err=1 and TYPE = 'mempage'

In most cases dl and err columns are 0 so two last select will return 0. I found out this query returns only one that is not what i expected. I found this solution:

Select count(*) as cnt,'s' as p from  page06 where dl = 1 and TYPE = 'mempage' union 
Select count(*),'d' as p  from  page06 where err = 1 and TYPE = 'mempage' union  
Select count(*),'f' as p   from  page06 where dl = 1 and err=1 and TYPE = 'mempage'

This query works perfectly but I have written codes in first format. I want to know why this happens and is there any solution (Except what I said) to solve this problem?
The reason I don’t want to use my solution is I have lots of written queries that I don’t want to (or even cannot) change them! what I’m seeking is some king of options to set to connection (like set names 'latin1';)

  • 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-07T21:45:48+00:00Added an answer on June 7, 2026 at 9:45 pm

    Use UNION ALL instead of UNION

    Check this post for a detailed explanation on the difference :
    What is the difference between UNION and UNION ALL?

    SELECT count(*) AS cnt FROM  page06 WHERE dl = 1 AND TYPE = 'mempage' UNION ALL
    SELECT count(*) AS cnt FROM  page06 WHERE err = 1 AND TYPE = 'mempage' UNION ALL
    SELECT count(*) AS cnt FROM  page06 WHERE dl = 1 AND err=1 AND TYPE = 'mempage'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query in my sql if (select count(*) from sys.columns where object_id
Basically if I had a mysql table with columns: id, type, content, version. There
I have the following query: SELECT location, step, COUNT(*), AVG(foo), YEAR(start), MONTH(start), DAY(start) FROM
In old mysql code, I had a query below which worked perfectly which is
I had a task to slide images from a mysql database using jquery slide
I have a simple stats query in mysql. I had it working using php
I had an old mysql code where it successfully inserted values into the database.
I had a question in MySQL, did it correctly. But the book code differs
Just had a discussion at work about the merits of using PostgreSQL over MySQL
I have just migrated to mysql 5.5.20 and I had a performance issue with

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.