473,326 Members | 2,102 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,326 software developers and data experts.

Problem With Select Statement ~ Can anyone Help?

Hello All,

I have this sql statement thats works in MSSQL when I call a function

function showNewProd(dispNum)

'Declare some variables
dim mySQL, rsTemp, tempStr, count

'Read Database
mySQL="SELECT TOP " & dispNum & " idProduct, description " _
& "FROM products " _
& "WHERE active = -1 " _
& "ORDER BY idProduct DESC "
set rsTemp = openRSexecute(mySQL)
do while not rsTemp.EOF

'Increment counter
count = count + 1

'Build display string
tempStr = tempStr _
& count & ". <a href=""" & urlNonSSL _
& "prodView.asp?idProduct=" & rsTemp("idProduct") & """>" _
& rstemp("description") _
& "</a><br>"

'Next Record
rsTemp.MoveNext

loop
call closeRS(rsTemp)

end function
I need to make the same function work with a mysql database, the problem I
am having is a problem with possibly the SELECT TOP statement, not working
with MYSQL but I am not sure how to fix this, can anyone help as I am a
little stuck.

Many thanks in advance.
Andie
Jul 20 '05 #1
16 3146
Andie wrote:
I need to make the same function work with a mysql database, the problem I
am having is a problem with possibly the SELECT TOP statement, not working
with MYSQL but I am not sure how to fix this, can anyone help as I am a
little stuck.


What does SELECT TOP do? ( Or what it is supposed to do in MySQL? )
Jul 20 '05 #2
Andie wrote:
I need to make the same function work with a mysql database, the problem I
am having is a problem with possibly the SELECT TOP statement, not working
with MYSQL but I am not sure how to fix this, can anyone help as I am a
little stuck.


What does SELECT TOP do? ( Or what it is supposed to do in MySQL? )
Jul 20 '05 #3
Thanks for the quick response..

Basically when I add a product to the database, the product is added to the
database with the idproduct field being an incremented file.

The fuction sorts the file in reverse order of idproduct and displays the
last (say 5) record products added to the database.

Hope this helps.

Andie
Jul 20 '05 #4
Thanks for the quick response..

Basically when I add a product to the database, the product is added to the
database with the idproduct field being an incremented file.

The fuction sorts the file in reverse order of idproduct and displays the
last (say 5) record products added to the database.

Hope this helps.

Andie
Jul 20 '05 #5
Andie wrote:
Basically when I add a product to the database, the product is added to the
database with the idproduct field being an incremented file.

The fuction sorts the file in reverse order of idproduct and displays the
last (say 5) record products added to the database.


Ok, in MySQL there is no TOP, there is LIMIT.

i.e.
select * from table order by id limit 5;

This would return first 5 rows in table. You can also rotate the order
and then limit would return last 5.
Jul 20 '05 #6
Andie wrote:
Basically when I add a product to the database, the product is added to the
database with the idproduct field being an incremented file.

The fuction sorts the file in reverse order of idproduct and displays the
last (say 5) record products added to the database.


Ok, in MySQL there is no TOP, there is LIMIT.

i.e.
select * from table order by id limit 5;

This would return first 5 rows in table. You can also rotate the order
and then limit would return last 5.
Jul 20 '05 #7
how would I rotate the order in MYSQL?

Andie
"Aggro" <sp**********@yahoo.com> wrote in message
news:BL***************@read3.inet.fi...
Andie wrote:
Basically when I add a product to the database, the product is added to the database with the idproduct field being an incremented file.

The fuction sorts the file in reverse order of idproduct and displays the last (say 5) record products added to the database.


Ok, in MySQL there is no TOP, there is LIMIT.

i.e.
select * from table order by id limit 5;

This would return first 5 rows in table. You can also rotate the order
and then limit would return last 5.

Jul 20 '05 #8
how would I rotate the order in MYSQL?

Andie
"Aggro" <sp**********@yahoo.com> wrote in message
news:BL***************@read3.inet.fi...
Andie wrote:
Basically when I add a product to the database, the product is added to the database with the idproduct field being an incremented file.

The fuction sorts the file in reverse order of idproduct and displays the last (say 5) record products added to the database.


Ok, in MySQL there is no TOP, there is LIMIT.

i.e.
select * from table order by id limit 5;

This would return first 5 rows in table. You can also rotate the order
and then limit would return last 5.

Jul 20 '05 #9
Andie wrote:
how would I rotate the order in MYSQL?


Sorry, I might use a little wrong term (English is not my first language.).

I mean, you can get the rows in opposite order, the same way you seem to
be using in your example. For example:

# get last 5 rows in table (by id)
select * from table order by id desc limit 5;
Jul 20 '05 #10
Andie wrote:
how would I rotate the order in MYSQL?


Sorry, I might use a little wrong term (English is not my first language.).

I mean, you can get the rows in opposite order, the same way you seem to
be using in your example. For example:

# get last 5 rows in table (by id)
select * from table order by id desc limit 5;
Jul 20 '05 #11
Ok, thanks aggro, you have been a great help, sorry I am being abit slow
today, being tired..

Andie
"Aggro" <sp**********@yahoo.com> wrote in message
news:0Z***************@read3.inet.fi...
Andie wrote:
how would I rotate the order in MYSQL?
Sorry, I might use a little wrong term (English is not my first

language.).
I mean, you can get the rows in opposite order, the same way you seem to
be using in your example. For example:

# get last 5 rows in table (by id)
select * from table order by id desc limit 5;

Jul 20 '05 #12
Ok, thanks aggro, you have been a great help, sorry I am being abit slow
today, being tired..

Andie
"Aggro" <sp**********@yahoo.com> wrote in message
news:0Z***************@read3.inet.fi...
Andie wrote:
how would I rotate the order in MYSQL?
Sorry, I might use a little wrong term (English is not my first

language.).
I mean, you can get the rows in opposite order, the same way you seem to
be using in your example. For example:

# get last 5 rows in table (by id)
select * from table order by id desc limit 5;

Jul 20 '05 #13
Hello Aggro (if you are still there)

I have used your advice and got one of the functions to work, but can you
suggest what is causing this problem
There error I am now getting is : Invalid use of group function...

Here is my sql statement:

mySQL = "SELECT a.idProduct, a.description " _
& "FROM cartRows a, cartHead b " _
& "WHERE a.idOrder = b.idOrder " _
& "AND (b.orderStatus='1' OR b.orderStatus='2' OR
b.orderStatus='7') " _
& "GROUP BY a.idProduct, a.description " _
& "ORDER BY SUM(a.quantity) DESC " _
& "limit " & dispnum

If I take the order by line out, it I don't get the error, but can you think
of a way I could get this to work..

Andie
"Andie" <an***@mansuntv.co.uk> wrote in message
news:f5*********************@wards.force9.net...
Ok, thanks aggro, you have been a great help, sorry I am being abit slow
today, being tired..

Andie
"Aggro" <sp**********@yahoo.com> wrote in message
news:0Z***************@read3.inet.fi...
Andie wrote:
how would I rotate the order in MYSQL?


Sorry, I might use a little wrong term (English is not my first

language.).

I mean, you can get the rows in opposite order, the same way you seem to
be using in your example. For example:

# get last 5 rows in table (by id)
select * from table order by id desc limit 5;


Jul 20 '05 #14
Hello Aggro (if you are still there)

I have used your advice and got one of the functions to work, but can you
suggest what is causing this problem
There error I am now getting is : Invalid use of group function...

Here is my sql statement:

mySQL = "SELECT a.idProduct, a.description " _
& "FROM cartRows a, cartHead b " _
& "WHERE a.idOrder = b.idOrder " _
& "AND (b.orderStatus='1' OR b.orderStatus='2' OR
b.orderStatus='7') " _
& "GROUP BY a.idProduct, a.description " _
& "ORDER BY SUM(a.quantity) DESC " _
& "limit " & dispnum

If I take the order by line out, it I don't get the error, but can you think
of a way I could get this to work..

Andie
"Andie" <an***@mansuntv.co.uk> wrote in message
news:f5*********************@wards.force9.net...
Ok, thanks aggro, you have been a great help, sorry I am being abit slow
today, being tired..

Andie
"Aggro" <sp**********@yahoo.com> wrote in message
news:0Z***************@read3.inet.fi...
Andie wrote:
how would I rotate the order in MYSQL?


Sorry, I might use a little wrong term (English is not my first

language.).

I mean, you can get the rows in opposite order, the same way you seem to
be using in your example. For example:

# get last 5 rows in table (by id)
select * from table order by id desc limit 5;


Jul 20 '05 #15
Andie wrote:
mySQL = "SELECT a.idProduct, a.description " _
& "FROM cartRows a, cartHead b " _
& "WHERE a.idOrder = b.idOrder " _
& "AND (b.orderStatus='1' OR b.orderStatus='2' OR
b.orderStatus='7') " _
& "GROUP BY a.idProduct, a.description " _
& "ORDER BY SUM(a.quantity) DESC " _
& "limit " & dispnum

If I take the order by line out, it I don't get the error, but can you think
of a way I could get this to work..


Please paste only the query text here so it will be easier to read. Try
to put the sum between "select" and "from", like this:

select id,sum(value) as summa from tablename group by id order by summa
desc;
Jul 20 '05 #16
Andie wrote:
mySQL = "SELECT a.idProduct, a.description " _
& "FROM cartRows a, cartHead b " _
& "WHERE a.idOrder = b.idOrder " _
& "AND (b.orderStatus='1' OR b.orderStatus='2' OR
b.orderStatus='7') " _
& "GROUP BY a.idProduct, a.description " _
& "ORDER BY SUM(a.quantity) DESC " _
& "limit " & dispnum

If I take the order by line out, it I don't get the error, but can you think
of a way I could get this to work..


Please paste only the query text here so it will be easier to read. Try
to put the sum between "select" and "from", like this:

select id,sum(value) as summa from tablename group by id order by summa
desc;
Jul 20 '05 #17

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

Similar topics

6
by: Dan Evans | last post by:
Hi, Can anyone help me on a little problem I am having with some SQL - in particular on a subquery. I am setting up a database in Access for a voluntary group which runs
10
by: JMorrell | last post by:
First post to this community so am not sure if this is the correct place. Here goes. I have a MS Access db that keeps track of employees sick and annual leave balances. In it, I have a report,...
7
by: CharlesEF | last post by:
Hi All, I have run into another problem that is eating my lunch. Should be simple but I am having one heck of a time. Please look at this SELECT statement: SELECT FROM States WHERE ] =...
5
by: Timppa | last post by:
Hi, Could anyone help me with my problem ? Environment: Access 2000 and Sql Server 2000. I have a stored procedure as follows: DROP table1 SELECT alias1.field1,alias2.field2,table2.field6...
4
by: Bradley Burton | last post by:
I'm using Allen Brown's code for audit logging (http://allenbrowne.com/AppAudit.html), but I'm having a problem. My aud table doesn't populate with the tracking info at all. I think it might be a...
2
by: scole954387 | last post by:
Hi, I have a problem. I have written a SQL statement that has a nested select case statement on the 'where' clause to condition the results. ...
8
by: Ian Mackenzie | last post by:
Hi Guys I am VERY new to DB2 and have created a workingdays function to return the working days between 2 dates, but I get some compiler errors when running it: CREATE FUNCTION WORKINGDAYS...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
6
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help with a combo box and this same code works on my first tab with a combo box. The error or problem i have is this code causes an index out of range error when i run it on my second combo...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.