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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:00:18+00:00 2026-05-30T20:00:18+00:00

here is my query $where_or = AND content_status = ‘Active’ AND content_post_status = ‘published’

  • 0

here is my query

$where_or = " 
                AND
                    content_status = 'Active'
                AND
                    content_post_status = 'published'
                AND
                    deleted = 0
                AND
                    content_type = '$type'
                ORDER BY content_created_at DESC ";

        $select = "content_id, content_title, content_short_description, content_url, content_created_at";

        $query = $this->db->query("
                (
                    SELECT $select
                    FROM tbl_content
                    WHERE 
                    content_category_id = 54
                    $where_or
                    LIMIT 3
                )
                UNION ALL 
                (
                    SELECT $select
                    FROM tbl_content
                    WHERE 
                    content_category_id = 55
                    $where_or
                    LIMIT 2
                )
                UNION ALL 
                (
                    SELECT $select
                    FROM tbl_content
                    WHERE 
                    content_category_id = 56
                    $where_or
                    LIMIT 2
                )
                UNION ALL 
                (
                    SELECT $select
                    FROM tbl_content
                    WHERE 
                    content_category_id = 57
                    $where_or
                    LIMIT 1
                )
                UNION ALL 
                (
                    SELECT $select
                    FROM tbl_content
                    WHERE 
                    content_category_id = 58
                    $where_or
                    LIMIT 1
                )
                UNION ALL 
                (
                    SELECT $select
                    FROM tbl_content
                    WHERE 
                    content_category_id = 60
                    $where_or
                    LIMIT 1
                )
                UNION ALL 
                (
                    SELECT $select
                    FROM tbl_content
                    WHERE 
                    content_category_id = 61
                    $where_or
                    LIMIT 1
                )
                UNION ALL 
                (
                    SELECT $select
                    FROM tbl_content
                    WHERE 
                    content_category_id = 118
                    $where_or
                    if content_type = 'article'
                    begin 
                        LIMIT 10
                    end
                )   
        ");

You can see in last UNION i want to put limit on if condition ..but its giving me error…how can i do that…please help..

  • 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-30T20:00:19+00:00Added an answer on May 30, 2026 at 8:00 pm

    You cannot do that with MySQL, at least not the way you are trying to. If you think about it
    this:

    if content_type = 'article'
    begin 
       LIMIT 10
    end
    

    doesn’t make sense. LIMIT is applied to a set not a single record. If what you wrote were valid SQL and your data contained both content that was true for content_type = ‘article’ and some that was false. What would you expect to happen?

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

Sidebar

Related Questions

I'm stuck with another coordinates related query here. I have a number of CSV
Here's the query: SELECT COUNT(*) AS c, MAX(`followers_count`) AS max_fc, MIN(`followers_count`) AS min_fc, MAX(`following_count`)
Here is my query Select Gender from Table The result pane shows 1 1
Here is the query that I am working on: SELECT `unitid`, `name` FROM apartmentunits
Here's my query: DECLARE @StartRow INT DECLARE @PageSize INT SET @StartRow = 1 SET
Here is my Query : select EmployeeName, EmployeeSalary from Employee2 for xml path('EmployeeDetails') returns
So firstly here's my query: ( NOTE:I know SELECT * is bad practice I
I was reading about refactoring a large slow SQL Query over here , and
Ok, here's a query that I am running right now on a table that
Here is the procedure, CREATE OR REPLACE PROCEDURE provsnXmlCmprsn ( encyNo SAS_PRO_CTL.AGENCYNO%TYPE, period SAS_PRO_CTL.PERIODE%TYPE)

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.