469,917 Members | 1,716 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

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 3017
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Dan Evans | last post: by
10 posts views Thread by JMorrell | last post: by
5 posts views Thread by Timppa | last post: by
4 posts views Thread by Bradley Burton | last post: by
2 posts views Thread by scole954387 | last post: by
8 posts views Thread by Ian Mackenzie | last post: by
6 posts views Thread by =?Utf-8?B?amVmZmVyeQ==?= | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.