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

  • Home
  • SEARCH
  • 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 6741369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:42:59+00:00 2026-05-26T11:42:59+00:00

1st query; both tables contain all categories_id s SELECT * FROM categories c, categories_description

  • 0

1st query; both tables contain all categories_ids

SELECT 
* 
FROM 
categories c,
categories_description cd 
WHERE c.categories_id = cd.categories_id 
ORDER BY sort_order, cd.categories_name

2nd query; this table maybe hold a categories_id

SELECT 
count(*) 
AS total 
FROM 
products_to_categories 
WHERE 
categories_id = "'+ catid +'"'

I need a way to row all categories from the first query (to make a list) and to give me a yes/no or 0/1 from the second query in one SQL query.

The result would look like this:

categories_id | categories_name | total(*)
    1         |    categorie1   |   21       
    2         |    categorie2   |   0 (if categories_id in  'products_to_categories' does not exist

I require it in the following code:

var dbSize = 5 * 1024 * 1024; // 5MB
var db = openDatabase("Oscommerce", "1.0", "Oscommerce Database", dbSize);

var categories={};

var list_str = '';
db.transaction(function (tx) {
    tx.executeSql('SELECT * FROM categories c,categories_description cd WHERE c.categories_id = cd.categories_id ORDER BY categories_id', [], function (tx, results) {
        list_str += '<ul data-role="listview" data-inset="true" data-theme="d">';
        var len = results.rows.length, i;

        for (i = 0; i < len; i++) {
            var r = results.rows.item(i);
            categories[r.categories_id] = r;
        }
        for(key in categories)
        {
            var parent = 0;  
            var value=categories[key];
            catId = value['categories_id'];
            catName = value['categories_name'];
            catImage = value['categories_image'];
            parentId = value['parent_id'];
            if (parentId == parent) 
            {
                list_str += '<li id="'+ catId +'"><a class="parentlink" parentid="'+ parentId +'" catid="'+ catId +'" catname="'+ catName +'"><h3>' + catName + '</h3><p>' + catImage + '</p></a></li>';
                ///i need to do an else around here if the rowed list has products
            }
        }
        list_str += '</ul>';

        $('#parents').html(list_str).find('ul').listview();
    }); 
});

The total output should generate something like this (watch the count bubbles in the list).

  • 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-26T11:43:00+00:00Added an answer on May 26, 2026 at 11:43 am

    This select should be what you want:

    SELECT 
     c.categories_id, cd.categories_name, 
     case when aa.total_per_id is null then 0
       else aa.total_per_id 
     end as total
    FROM categories as c
       join categories_description as cd on c.categories_id = cd.categories_id
       left join (
        select a.categories_id, 
         count(*) as total_per_id from product_to_categories a
        group by a.categories_id ) as aa on aa.categories_id = c.categories_id
    ORDER BY c.sort_order, cd.categories_name;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The query: SELECT ct_cid as level1 FROM cat_tree WHERE ct_sid=$sid_int AND ct_parent =$cid_int) UNION
I currently have this query set-up: SELECT topic.content_id, topic.title, image.location FROM mps_contents AS topic
I tried the simple join join query.txt source.tab Based on 1st colum in both
When i execute a query with Flex which contain some expression like select count(id)
I have a MySQL query that selects data from multiple tables and then orders
Is query caching/entity caching are related to both 1st and 2nd level caches or
I have 2 tables: 1st holds employees (of ones in any position) and the
I have a query with a self join that looks like this, select t1.
if select * from table where x=1 returns 0 rows, then I need select
Which one of below query has better performance? What's the upside/downside for both query?

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.