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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:06:54+00:00 2026-05-30T16:06:54+00:00

hi have an category table categoryId Categoryname Type these are column name’s so i

  • 0

hi have an category table

categoryId
Categoryname
Type 

these are column name’s so i need to show all categories where type=’card’ but General category on top here is my code

SELECT * FROM `tbl_Catagory` 
where CatagoryId=1 and type='Card' 
union select * from tbl_Catagory` 
where CatagoryId !=1 and type='Card' 
order by CatagoryId desc`

here i get desc order but general on bottom so what i need is general category on top with the remaining categories displayed in descending order based on categoryId

  • 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-30T16:06:55+00:00Added an answer on May 30, 2026 at 4:06 pm

    You don’t need UNION:

    SELECT * 
    FROM tbl_Catagory
    WHERE type='Card'
    ORDER BY (CatagoryId=1) DESC 
           , CatagoryId DESC
    

    This works because True evaluates to 1 and False to 0. The first part of the ORDER BY makes sure that only those with CatagoryId=1 are ordered first. Then, all the rest which are subsequently ordered by their CategoryId in descending order.

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

Sidebar

Related Questions

I have three tables Category, Movies and RelCatMov Category-table categoryid, categoryName 1 thriller 2
I have the following hierarchical table: Table Category: CategoryId, ParentCategoryId, CategoryName 1, null, SomeRoot
I have a 2 Table. Product ProductName CategoryID Category ID CategoryName I'm filling combobox
I have 4 tables Table: Category CategoryID (int) Name (varchar) Table: Products ProductID (int)
I have some tables with data: Category CategoryID CategoryName 1 Home 2 Contact 3
I have tables Product ( ID, CategoryID, ... ) Category ( ID, Name, ..
Lets suppose that I have a Category table with a column that holds the
In my database I have a table Category, with columns Id, CategoryName, ParentCategoryId, where
I have the following tables Entity id,name,categoryid 21,Blah,1 EntityCategory (Enum table) id, name 1,New
I have table product(table name) product_id product_name product_image product_price product_description category_id category(table name )

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.