473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

aql query

i'm using access and got a table with the fields:
CatName, CatOrder and StoreID.
i need to get the list of all the CatName and to know how many result i got
or what is the max value in the CatOrder field.
can it be done with only one query or i need to do the max query first?
Nov 13 '05 #1
15 1492
"Sagi" <sa**@schieber.net> wrote in message
news:42******@news.bezeqint.net...
i'm using access and got a table with the fields:
CatName, CatOrder and StoreID.
i need to get the list of all the CatName and to know how many result i
got or what is the max value in the CatOrder field.
can it be done with only one query or i need to do the max query first?


A little unclear what you want but this:

SELECT [tblOrders].[CatName], Count([tblOrders].[CatName]) AS numCatName,
Max([tblOrders].[CatOrder]) AS maxCatOrder
FROM tblOrders
GROUP BY [tblOrders].[CatName];

will give you:

one row for each CatName in the table
column 1 will be the CatName
Column 2 will be the number of times each CatName appears in the table
Column 3 will be the maximum value of CatOrder for that CatName.

Mike
Nov 13 '05 #2
sorry, this i know, but it's not what i need. i will try again.
i need to show all the rows and to know the max(CatOrder) for all the rows.
when i do it i get only one row back, the one that got the max(CatOrder).
i need to know the max(CatOrder) and to get all the rows back too.
do i must use 2 seperated queries??

"Sagi" <sa**@schieber.net> wrote in message
news:42******@news.bezeqint.net...
i'm using access and got a table with the fields:
CatName, CatOrder and StoreID.
i need to get the list of all the CatName and to know how many result i
got or what is the max value in the CatOrder field.
can it be done with only one query or i need to do the max query first?

Nov 13 '05 #3
sorry, this i know, but it's not what i need. i will try again.
i need to show all the rows and to know the max(CatOrder) for all the rows.
when i do it i get only one row back, the one that got the max(CatOrder).
i need to know the max(CatOrder) and to get all the rows back too.
do i must use 2 seperated queries??

"Mike MacSween" <mi***************************@btinternet.com> wrote in
message news:42***********************@news.aaisp.net.uk.. .
"Sagi" <sa**@schieber.net> wrote in message
news:42******@news.bezeqint.net...
i'm using access and got a table with the fields:
CatName, CatOrder and StoreID.
i need to get the list of all the CatName and to know how many result i
got or what is the max value in the CatOrder field.
can it be done with only one query or i need to do the max query first?


A little unclear what you want but this:

SELECT [tblOrders].[CatName], Count([tblOrders].[CatName]) AS numCatName,
Max([tblOrders].[CatOrder]) AS maxCatOrder
FROM tblOrders
GROUP BY [tblOrders].[CatName];

will give you:

one row for each CatName in the table
column 1 will be the CatName
Column 2 will be the number of times each CatName appears in the table
Column 3 will be the maximum value of CatOrder for that CatName.

Mike

Nov 13 '05 #4
Sagi wrote:
sorry, this i know, but it's not what i need. i will try again.
i need to show all the rows and to know the max(CatOrder) for all the rows.
when i do it i get only one row back, the one that got the max(CatOrder).
i need to know the max(CatOrder) and to get all the rows back too.
do i must use 2 seperated queries??


Air SQL (refers to your table as Table1)

SELECT t.*, sq.MaxCatOrder
FROM Table1 t
LEFT JOIN
[SELECT Max(CatOrder) AS MaxCatOrder FROM Table1]. sq
ON sq.MaxCatOrder>=t.CatOrder

--
--
Lyle

"The aim of those who try to control thought is always the same. They
find one single explanation of the world, one system of thought and
action that will (they believe) cover everything; and then they try to
impose that on all thinking people."
- Gilbert Highet
Nov 13 '05 #5
"Sagi" <sa**@schieber.net> wrote in message
news:42******@news.bezeqint.net...
sorry, this i know, but it's not what i need. i will try again.
i need to show all the rows and to know the max(CatOrder) for all the
rows.
when i do it i get only one row back, the one that got the max(CatOrder).
i need to know the max(CatOrder) and to get all the rows back too.
do i must use 2 seperated queries??


SELECT tblOrders.CatName, Count(tblOrders.CatName) AS numCatName,
First((SELECT max(CatOrder) FROM tblOrders)) AS maxAllCatOrder
FROM tblOrders
GROUP BY tblOrders.CatName;

Maybe?

It's still not entirely clear what you want. When you say 'i need to show
all the rows ' do you mean each and every row in the table? Or one row for
each CatName (Which is what the above will give you)?

Mike
Nov 13 '05 #6
lets say that i got 12 rows of catID 1 and catOrder (numbers between 1-30)
and 12 rows of cat iD 2 and catOrder (numbers between 1-30) and .
i need get all the 24 records back and to know what is the the max value of
the catOrder for each catID.
can it be done with one query?
"Mike MacSween" <mi***************************@btinternet.com> wrote in
message news:42***********************@news.aaisp.net.uk.. .
"Sagi" <sa**@schieber.net> wrote in message
news:42******@news.bezeqint.net...
sorry, this i know, but it's not what i need. i will try again.
i need to show all the rows and to know the max(CatOrder) for all the
rows.
when i do it i get only one row back, the one that got the max(CatOrder).
i need to know the max(CatOrder) and to get all the rows back too.
do i must use 2 seperated queries??


SELECT tblOrders.CatName, Count(tblOrders.CatName) AS numCatName,
First((SELECT max(CatOrder) FROM tblOrders)) AS maxAllCatOrder
FROM tblOrders
GROUP BY tblOrders.CatName;

Maybe?

It's still not entirely clear what you want. When you say 'i need to show
all the rows ' do you mean each and every row in the table? Or one row for
each CatName (Which is what the above will give you)?

Mike

Nov 13 '05 #7
So where did CatID come from?

"Sagi" <sa**@schieber.net> wrote in message
news:42********@news.bezeqint.net...
lets say that i got 12 rows of catID 1 and catOrder (numbers between 1-30)
and 12 rows of cat iD 2 and catOrder (numbers between 1-30) and .
i need get all the 24 records back and to know what is the the max value
of the catOrder for each catID.
can it be done with one query?
"Mike MacSween" <mi***************************@btinternet.com> wrote in
message news:42***********************@news.aaisp.net.uk.. .
"Sagi" <sa**@schieber.net> wrote in message
news:42******@news.bezeqint.net...
sorry, this i know, but it's not what i need. i will try again.
i need to show all the rows and to know the max(CatOrder) for all the
rows.
when i do it i get only one row back, the one that got the
max(CatOrder).
i need to know the max(CatOrder) and to get all the rows back too.
do i must use 2 seperated queries??


SELECT tblOrders.CatName, Count(tblOrders.CatName) AS numCatName,
First((SELECT max(CatOrder) FROM tblOrders)) AS maxAllCatOrder
FROM tblOrders
GROUP BY tblOrders.CatName;

Maybe?

It's still not entirely clear what you want. When you say 'i need to show
all the rows ' do you mean each and every row in the table? Or one row
for each CatName (Which is what the above will give you)?

Mike


Nov 13 '05 #8
"Lyle Fairfield" <ly******@yahoo.ca> wrote in message
news:4S****************@read1.cgocable.net...
Sagi wrote:
sorry, this i know, but it's not what i need. i will try again.
i need to show all the rows and to know the max(CatOrder) for all the
rows.
when i do it i get only one row back, the one that got the max(CatOrder).
i need to know the max(CatOrder) and to get all the rows back too.
do i must use 2 seperated queries??


Air SQL (refers to your table as Table1)

SELECT t.*, sq.MaxCatOrder
FROM Table1 t
LEFT JOIN
[SELECT Max(CatOrder) AS MaxCatOrder FROM Table1]. sq
ON sq.MaxCatOrder>=t.CatOrder


I don't think he wants that Lyle.

SELECT *
FROM tblOrders AS t
LEFT JOIN [SELECT CatID, Max(CatOrder) AS MaxCatOrder FROM tblOrders GROUP
BY CatID]. AS sq
ON t.CatID = sq.CatID;

perhaps

Mike
Nov 13 '05 #9
"Lyle Fairfield" <ly******@yahoo.ca> wrote in message
news:4S****************@read1.cgocable.net...

In fact

SELECT *
FROM tblOrders AS t INNER JOIN [SELECT CatID, Max(CatOrder) AS MaxCatOrder
FROM tblOrders GROUP BY CatID]. AS sq ON t.CatID = sq.CatID;

without the left join.
Nov 13 '05 #10
"Sagi" <sa**@schieber.net> wrote in message
news:42********@news.bezeqint.net...
lets say that i got 12 rows of catID 1 and catOrder (numbers between 1-30)
and 12 rows of cat iD 2 and catOrder (numbers between 1-30) and .
i need get all the 24 records back and to know what is the the max value
of the catOrder for each catID.
can it be done with one query?


Does a particular value of CatID always = a particular value for CatName?

If so then that should be in a seperate table. I think. Depending what
CatOrder means, and StoreID.

Mike
Nov 13 '05 #11
i got a field that called CatID with values (1 or 2).
i got a field that called CatOrder with values (1-30)
i got a field that called CatName with the names of the categories.

i need to print out all the names of the categories ordered by CatID and
CatOrder and to print out the maximum value max(CatOrder) when catID=1 and
Max(catOrder) when catID = 2.
can it be done with only one query

thanks

sagi

"Mike MacSween" <mi***************************@btinternet.com> wrote in
message news:42***********************@news.aaisp.net.uk.. .
"Sagi" <sa**@schieber.net> wrote in message
news:42********@news.bezeqint.net...
lets say that i got 12 rows of catID 1 and catOrder (numbers between
1-30) and 12 rows of cat iD 2 and catOrder (numbers between 1-30) and .
i need get all the 24 records back and to know what is the the max value
of the catOrder for each catID.
can it be done with one query?


Does a particular value of CatID always = a particular value for CatName?

If so then that should be in a seperate table. I think. Depending what
CatOrder means, and StoreID.

Mike

Nov 13 '05 #12
"Sagi" <sa**@schieber.net> wrote in message
news:42********@news.bezeqint.net...
i got a field that called CatID with values (1 or 2).
i got a field that called CatOrder with values (1-30)
i got a field that called CatName with the names of the categories.

i need to print out all the names of the categories ordered by CatID and
CatOrder and to print out the maximum value max(CatOrder) when catID=1 and
Max(catOrder) when catID = 2.
can it be done with only one query


try this

SELECT *
FROM tblOrders AS t INNER JOIN [SELECT CatID, Max(CatOrder) AS MaxCatOrder
FROM tblOrders GROUP BY CatID]. AS sq ON t.CatID = sq.CatID;
Nov 13 '05 #13
is there a way i can send you the database, my english isn't to good, sorry,
not my first language.

"Mike MacSween" <mi***************************@btinternet.com> wrote in
message news:42***********************@news.aaisp.net.uk.. .
"Sagi" <sa**@schieber.net> wrote in message
news:42********@news.bezeqint.net...
i got a field that called CatID with values (1 or 2).
i got a field that called CatOrder with values (1-30)
i got a field that called CatName with the names of the categories.

i need to print out all the names of the categories ordered by CatID and
CatOrder and to print out the maximum value max(CatOrder) when catID=1
and Max(catOrder) when catID = 2.
can it be done with only one query


try this

SELECT *
FROM tblOrders AS t INNER JOIN [SELECT CatID, Max(CatOrder) AS MaxCatOrder
FROM tblOrders GROUP BY CatID]. AS sq ON t.CatID = sq.CatID;

Nov 13 '05 #14
tblCat
autoID CatID CatOrder CatName
1 1 1 lamp
2 2 6 ship
3 2 5 ggjh
4 1 4 hhuhui
5 1 3 jljjj
6 2 8 fdsm;s

i need to know that 8 is the higest number for catID= 2 and 4 is the highest
number for catID 1 and to print out all the records.
is that make sence??

sagi

"Mike MacSween" <mi***************************@btinternet.com> wrote in
message news:42***********************@news.aaisp.net.uk.. .
"Sagi" <sa**@schieber.net> wrote in message
news:42********@news.bezeqint.net...
i got a field that called CatID with values (1 or 2).
i got a field that called CatOrder with values (1-30)
i got a field that called CatName with the names of the categories.

i need to print out all the names of the categories ordered by CatID and
CatOrder and to print out the maximum value max(CatOrder) when catID=1
and Max(catOrder) when catID = 2.
can it be done with only one query


try this

SELECT *
FROM tblOrders AS t INNER JOIN [SELECT CatID, Max(CatOrder) AS MaxCatOrder
FROM tblOrders GROUP BY CatID]. AS sq ON t.CatID = sq.CatID;

Nov 13 '05 #15
i think this one is working
thank you so so so much

sagi
"Mike MacSween" <mi***************************@btinternet.com> wrote in
message news:42***********************@news.aaisp.net.uk.. .
"Sagi" <sa**@schieber.net> wrote in message
news:42********@news.bezeqint.net...
i got a field that called CatID with values (1 or 2).
i got a field that called CatOrder with values (1-30)
i got a field that called CatName with the names of the categories.

i need to print out all the names of the categories ordered by CatID and
CatOrder and to print out the maximum value max(CatOrder) when catID=1
and Max(catOrder) when catID = 2.
can it be done with only one query


try this

SELECT *
FROM tblOrders AS t INNER JOIN [SELECT CatID, Max(CatOrder) AS MaxCatOrder
FROM tblOrders GROUP BY CatID]. AS sq ON t.CatID = sq.CatID;

Nov 13 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
4
by: Diamondback | last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has descriptive information about the widgets while the VERSIONS table contains IDs relating to different iterations of those widgets...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.