Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> A Mysql Quiestion
m_rahman
post Feb 24 2005, 01:46 AM
Post #1


Newbie [Level 1]
*

Group: Members
Posts: 11
Joined: 23-February 05
Member No.: 3,929



hello. a table contains one int column like this:

5
19
22
60
74
80
81
109
120


and so on. notice that these numbers are incrementing, but not with a fixed amount each time.

now, i need to locate the record that a particular number is larger than it, for example, when i query with 40, it returns 22 (because it's the lower number just before my 40).
example2: when quering with 70, it returns 60.


so now i need a select query to achieve this. please support and any help is appreciated.
Go to the top of the page
 
+Quote Post
m_rahman
post Feb 24 2005, 04:18 AM
Post #2


Newbie [Level 1]
*

Group: Members
Posts: 11
Joined: 23-February 05
Member No.: 3,929



well, it wasn't a particular mysql question so far. it was just a sql language question. so, i got the answer alone, just two queries, one to select all the lower values , which is a sub query, and the other gets the max of them, and this is the main query. like this:

SELECT max(num) from (select num from my_table where num <= 90 )


with access, oarcle or sql server it will run NO PROBLEM!!!

now we turn to mysql specifications, looks like there is no way of doing that thing. two hours searching with google, and all results were from people asking , and thoses who replied them were all pitying them, crying for them, and not sure of their answers.

i also noticed that my post is the only question post. all the other topics here are advices and new ideas. sorry guys. but you really put me down sad.gif
Go to the top of the page
 
+Quote Post
bjrn
post Feb 24 2005, 08:43 PM
Post #3


Super Member
*********

Group: Members
Posts: 378
Joined: 8-January 05
Member No.: 3,174



CODE
select max(num) from my_table where num <= 90

would work just as well as the query you posted. Perhpas even better, because it doesn't use a sub-query.

I don't see why this wouldn't work with MySQL. Are you having problems executing it in any way? Are you getting an error message, and if so, what is it?
Go to the top of the page
 
+Quote Post
m_rahman
post Feb 25 2005, 12:48 AM
Post #4


Newbie [Level 1]
*

Group: Members
Posts: 11
Joined: 23-February 05
Member No.: 3,929



look. select max(num) from my_table where num <= 90 works ok, yes i know that i don't need a sub-query to get the max value, and i don't just need that max value, i need the field value next to it. they are two columns (num and column2) and sorry i didn't mention that. I just wanted to give an examble of using sub-queries.

i meant: select column2 from my_table where num=( select max(num) from my_table where num <= 90 )
anyway i got a solution for this, i run the first query
select max(num) from my_table where num <= 90
and store the result in an outer variable. then query again with this variable.
thanks much smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Mysql Database Setup : Setting Up Mysql Database(6)
  2. Complete Login System(57)
  3. Increment A Mysql Column(7)
  4. Import From Excel File Into Mysql Database(9)
  5. Mysql Database Size(6)
  6. Subquery In Mysql(5)
  7. Check Referrer To Prevent Linking Yours From Other Sites(8)
  8. Is It Possible To Access The Mysql Remotely?(10)
  9. Qupis : Free Hosting With Php, Mysql, Cpanel. (one Line Text Ad At Bottom)(41)
  10. Mysql Won't Update(4)
  11. Mysql + Php Question(5)
  12. Tools Needed!(9)
  13. Database With Mysql++(7)
  14. Mysql-essential-5.0.51 Installion Problem(2)
  15. Mysql, Php, Apache Downloads And Setup Was A Nightmare(10)
  1. Html Form!(4)
  2. Mysql(2)
  3. Mysql Error(3)
  4. Create Table - Mysql Code - Help(1)
  5. Remote Access Mysql(8)
  6. Please Explain Me Mysql(4)
  7. How Do I Find My Mysql Password? [resolved](5)
  8. It Went Well For A While(5)
  9. Mysql Db Is Down Getting Following Error(2)
  10. Need Advice On Setting Up Mysql Database.(3)
  11. The Only Reason I Choose Ms Sql Server Rather Than Mysql(0)
  12. Mysql Database Not Working(3)
  13. Creating A Php Login System Using Mysql(9)


 



- Lo-Fi Version Time is now: 6th September 2008 - 06:14 AM