473,386 Members | 1,734 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,386 software developers and data experts.

Best solution? (too few parameters. Expected 1.)

I am making an app which has to work on a number of DB systems. This
requires simple SQL which will work almost everywhere.
Something like this does not work in MS access

select b.name,a.code,count(a.code) as x
from a, b
where....
group by code
order by x

So I have to do this

--- same--..
group by code,name
order by count(a.code)

Or is there a better solution?
I wonder hot the 2nd count is translated, e.g. when I have large tables
and different systems, it will run it 2 times, and become slower.

Sonnich

Jan 3 '06 #1
2 1771
"Sonnich" <so************@elektrobit.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
I am making an app which has to work on a number of DB systems. This
requires simple SQL which will work almost everywhere.
Something like this does not work in MS access

select b.name,a.code,count(a.code) as x
from a, b
where....
group by code
order by x

So I have to do this

--- same--..
group by code,name
order by count(a.code)

Or is there a better solution?
I wonder hot the 2nd count is translated, e.g. when I have large tables
and different systems, it will run it 2 times, and become slower.

Sonnich


The first has "group by code" while the second has "group by code,name".
Could it be that you did not mean to write this and in fact you question is
can I sort on an alias column?
The short answer is no, but you could do the following to query the sample
Northwind database to get a list of customers with those that had placed the
most orders at the top of the list. Here we use the column number in the
order by clause.

Original:

SELECT Customers.CustomerID, COUNT(*) AS Qty
FROM Customers INNER JOIN Orders ON
Customers.CustomerID=Orders.CustomerID
GROUP BY Customers.CustomerID
ORDER BY COUNT(*) DESC

Changed to:

SELECT Customers.CustomerID, COUNT(*) AS Qty
FROM Customers INNER JOIN Orders ON
Customers.CustomerID=Orders.CustomerID
GROUP BY Customers.CustomerID
ORDER BY 2 DESC
As to how much any application might slow down, I think you have to just try
it out for yourself with sample data. Even if it did double the time (which
I'm not sure it would), you also need to look at the absolute time - e.g.
another 0.3 seconds may be of no consequence. In cases where the speed of a
query is an absolute must, and you have no other choice you can break the
normalisation rules and store a calculated column as an indexed field in the
table. Of course, that brings its own issues with it, but nothing will beat
it for speed.
Jan 3 '06 #2
Hmmm, I better explain a bit here:

GROUP BY Customers.CustomerID, Customers.something_else
The point: I found, that if I retrive more than one field, I need to
group by all of them, but when using MySQL I don't. This is simple, and
will work everywhere.
If there would be any question here, then it would be something like:
what is standard sql? (e.g. SQL-92)?

ORDER BY COUNT(*) DESC
This is more interesting - I found, that in MySQL I can have a generic
(?) field here, such as "count(something) as x", but it does not work
with MS Access, there I have to use the "count..." in both places,
which eventually might result in the DB reading that field/running that
action twice.
Again, I wonder what is standard with SQL....

Anyway, the solutitions described here works with MS Access, I haven't
had an opputunity to test it on MySQL again.

HTH
Sonnich

Jan 3 '06 #3

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

Similar topics

2
by: Robert Mark Bram | last post by:
Hi All! My ASP page below receives the following error: Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80040E10) Too few parameters. Expected 2. /polyprint/test.asp, line 31 ...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
7
by: Dee | last post by:
Running an AfterUpdate event procedure, I get the following error: "Too few parameters. Expected 1." My code is as follows: Private Sub DealerID_AfterUpdate() Dim db As DAO.Database
2
by: Susan Bricker | last post by:
Greetings Experts ... I have a routine that is invoked when a command button is clicked. The button is located in a form that is tied to a table of Project records. Each Project Record has 0 to...
8
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to...
22
by: M K | last post by:
Heres my SP: ( i am trying to add more than 1 field but get the same error no matter how many i try to add, i thought i would try to insert the primary key only and work up from there but the...
1
by: Richard Hollenbeck | last post by:
I wonder what I'm missing? I really feel like a retard because I've been screwing with some code for a very long time. I just must be missing something very simple. In the following example,...
4
by: HeislerKurt | last post by:
I'm getting the infamous error, "Too few parameters. Expected 2", when executing an update SQL statement in VBA. I assume it's a SQL syntax issue, but I can't find the problem, and I used a VBA...
2
by: Ben Joyce | last post by:
Hi all. I'm confused as to what the best or expected approch is to Web Service design under .Net, mainly with regards to Methods and Parameters. This is a bit awkward to explain so please bear...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.