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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:58:30+00:00 2026-06-12T10:58:30+00:00

I have a category table in MySql database that holds the following data. id

  • 0

I have a category table in MySql database that holds the following data.

id  name                      parent
-------------------------------------
1   Web development           0
2   Application development   0
3   Linux                     0
4   Misc                      0
5   Php                       1
6   Mysql                     1
7   Javascript                1
8   CSS                       1
9   C plus plus               2
10  wxWidgets                 2
11  Tutorials                 3
12  My thoughts               4
13  Java                      1
14  JSP                       13
15  Spring                    14
16  Spring 3.0                15
17  Spring 3.1                15
18  JSF                       13
19  Oracle                    0
20  Oracle 8i                 19
21  Oracle 91                 19
22  JSF 2.0                   18
23  JSF 2.2                   18

I need the following output.

5   Php                       1
9   C plus plus               2
11  Tutorials                 3
12  My thoughts               4
6   Mysql                     1
7   Javascript                1
8   CSS                       1
10  wxWidgets                 2
22  JSF 2.0                   18
23  JSF 2.2                   18
16  Spring 3.0                15
17  Spring 3.1                15
20  Oracle 8i                 19
21  Oracle 91                 19

The result set should contain only the last level of each category. This can be done using a function in MySql. but is there a way to achieve this using an SQL query only?

  • 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-12T10:58:32+00:00Added an answer on June 12, 2026 at 10:58 am

    please check it .. It will work

    SELECT id, name, parent
    FROM category 
    WHERE id NOT 
    IN ( SELECT parent FROM category ) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really upset with Hibernate! I have a database table (mysql) that holds parent-child
Lets suppose that I have a Category table with a column that holds the
I have defined a web service that will return the data from my mysql
I have a database table with 6 fields that holds information about restaurants: id
I have a Database with a category table using the Nested Approach in MySql.
I have two tables in a Mysql database. PACKAGES: ID (auto_increment) CATEGORY (INT) NAME
I have a MySQL table like id | text | category | active I
I have the following hierarchical table: Table Category: CategoryId, ParentCategoryId, CategoryName 1, null, SomeRoot
So, I am modeling a database using MySQL Workbench. I have a table called
I have something like Facebook's Wall build on PHP that uses MySQL database. Structure:

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.