I'm trying to list my categories and how many items are in each
category. I'm not much on sub queries. How can I combine these two
items. I'd like to display the category and the corresponding number of
items in each
Cats:
Select
Category.Catego ryID,
Category.Catego ry,
Category.Sortin g
From
Category
Order By
Category.Sortin g Desc
Items:
Select Count(Listings. CategoryID)
From
Listings
Group By
Listings.Catego ryID
I've tried the following but can't get it to work:
Select
Category.Catego ryID,
Category.Catego ry,
Category.Sortin g,
(Select Count(Listings. CategoryID)
From
Listings WHERE Listings.Catego ryID = Category.Catego ryID) AS cnt
From
Category
Order By
Category.Sortin g Desc 7 3531
Barkster wrote: I'm trying to list my categories and how many items are in each category. I'm not much on sub queries. How can I combine these two items. I'd like to display the category and the corresponding number of items in each
Cats: Select Category.Catego ryID, Category.Catego ry, Category.Sortin g From Category Order By Category.Sortin g Desc
Items: Select Count(Listings. CategoryID) From Listings Group By Listings.Catego ryID
I've tried the following but can't get it to work:
Select Category.Catego ryID, Category.Catego ry, Category.Sortin g, (Select Count(Listings. CategoryID) From Listings WHERE Listings.Catego ryID = Category.Catego ryID) AS cnt From Category Order By Category.Sortin g Desc
It depends on your database - both which database and what version you're using.
Since this isn't a PHP question, try asking in a newsgroup for your database.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== ===
Yeah so used to posting here since I'm building in php, anyway it is
mysql 4
Select
Category.Catego ryID,
Category.Catego ry,
Category.Sortin g,
Count(Listings. CategoryID)
From
Category LEFT JOIN Listings on(Listings.Cat egoryID=categor y.CategoryID)
Order By
Category.Sortin g Desc
I was hoping it was that simple but when I run that I get an error:
Mixing of a GROUP colums (min(), max(), Count()) with no GROUP columns
is illegal if there is no GROUP BY clause
I'm trying do display something like this, where number of items in
each category is in parenthesis.
Category1(25)
Category2(57)
Category3(240)
My fault,
at the end of select you need to add groub by Category.Catego ryID
and you will get what you need.
My fault,
at the end of select you need to add "group by Category.Catego ryID"
and you will get what you need.
Figured it out, was close to what you mentioned
Select
Category.Catego ryID,
Category.Catego ry,
Category.Sortin g,
Count(Listings. CategoryID) as cnt
From
Category LEFT JOIN Listings on(Listings.Cat egoryID=Categor y.CategoryID)
Group By
Category.Catego ryID
Order By
Category.Sortin g Asc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: knoak |
last post by:
Hi there,
I have a small question:
I have a table with lots of rows in it. Of course all have a different id,
but each can be assigned to a certain category. Categories correspond
with 1 - 10.
So a row looks like this: 'unique id | 4'
What i want is to do a count how much rows belong to a certain category.
|
by: Mark |
last post by:
Hi, I have a Access database with two tables; a category table and an images
table. In the Category table I have a field for Index number and a field for
Categories. The images table has a field for all the images and a field to
specify what category the images are assigned to.
I am trying to write a simple Select query that will return a list of
Categories from my Category table, and in the second colum a count of the
number of images...
|
by: mfyahya |
last post by:
Hi,
I have a `category` table with columns cat_id and cat_name. And another
`items` table with columns item_id, item_name and cat_id.
I want a query which will select display each category name and the
number of items in that category. I could do this in two sql
statements, is it possible to do it in one?
Thanks~
|
by: Anne |
last post by:
Hi
I have got a table with some sales transactions. It has got 3 fields
1) Ordernumber
2) Item number
3) Shippingdate
Now I want to make ONE (not two) query that shows how many different orders
quarterly, and at the same time how many different item numbers used in each
quarter.
|
by: Chad A. Beckner |
last post by:
Hey all,
Does anyone have an example of where I can find ASP .NET code for creating
categories followed by the count (number of items in the category) page? I
can't find an example! :-( and example of what I am looking for can be
found at http://www.411asp.net/, looking like the following:
Web Applications (272)
Content Managers, Forum, E-Commerce, ...
| |
by: Barkster |
last post by:
I'm trying to list my categories and how many items are in each
category. I'm not much on sub queries. How can I combine these two
items. I'd like to display the category and the corresponding number of
items in each
Cats:
Select
Category.CategoryID,
Category.Category,
|
by: acorn71 |
last post by:
Hello,
I need to write a SELECT statement that will display the most popular
categories.
This means I need a 'category count' for each of the messages in the
messages table, and I don't know how to do this.
Here is the structure of the 2 tables:
|
by: googletired |
last post by:
Ok,
I need to be able to count the # of items for each category and have it display.
So say i have a left menu that displays that category name for cat in the current issue.xml for instance en_print_200802.xml which is called form a seperate .xml volissue.xml beside each name i want to display the # of items in each category.
<?xml version="1.0" encoding="utf-8"?>
<vol_issue vol_issue_id="200802">
...
|
by: winzone |
last post by:
Hi All,
Now i use the following code to print the data in C# 2005 application.
But i face the problem is total page number at the begining of first page. They want to get page number like : Page : 1 of 15.
Is there any suggesting how to get total page number.
Public int y = 0;
Public int LineCount = 0;
int yPosition = 50;
e.Graphics.DrawString("Summary of Image Data", drawHeaderFont, drawBrush, 50, yPosition,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |