SitePoint Sponsor |
|
User Tag List
Results 1 to 11 of 11
Thread: SYNTAX help
-
Jan 18, 2005, 13:09 #1
- Join Date
- Apr 2004
- Location
- Boston
- Posts
- 482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
SYNTAX help
I'm not sure how to word this query.
i need it to say something like
select column1 from tablename where colum2= MIN(column2)
in other words i need it to select column info from column 1 where it is = to the lowest value in column 2.
the value of column 2 will change everyday but i already have that part working.
thank you.
Also can i tell it to grab 2 rows of info?
-
Jan 18, 2005, 13:19 #2
-
Jan 18, 2005, 13:27 #3
- Join Date
- Apr 2004
- Location
- Boston
- Posts
- 482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thank you
-
Jan 18, 2005, 13:48 #4
- Join Date
- Apr 2004
- Location
- Boston
- Posts
- 482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
can i tell it to grab 2 rows of info?
-
Jan 18, 2005, 13:59 #5
- Join Date
- Oct 2003
- Location
- St. Catharines, ON Canada
- Posts
- 1,708
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How do you mean? If there is more than one row in the table with the same min value for column two then all rows are returned containing that value. If you want to limit which ones are returned how do you choose? If it doesn't matter other than you want to show two rows for col1 that have same min value for col2 then just add a LIMIT 2 at the end of the query.
-
Jan 18, 2005, 14:08 #6
- Join Date
- Apr 2004
- Location
- Boston
- Posts
- 482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
basically I just want to pull the information for the two rows that have the lowest value. they dont necessarily have to have the same value.
-
Jan 18, 2005, 14:58 #7
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
select column1,column2 from tablename
order by column2 limit 2
-
Jan 19, 2005, 06:52 #8
- Join Date
- Apr 2004
- Location
- Boston
- Posts
- 482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by r937
This query works when i put it in Dreamweaver or MYSQL CC but when i put the page to the browser it gives me this message:
You have an error in your SQL syntax near 'LIMIT 0, 2' at line 1
-
Jan 19, 2005, 07:43 #9
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
"put the page to the browser" ????
any chance you could show the actual query?
-
Jan 19, 2005, 12:17 #10
- Join Date
- Apr 2004
- Location
- Boston
- Posts
- 482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by r937
sure here it is:
$query_gettest = "SELECT `test` FROM `test_track` WHERE `cat`= '$cat' AND `speed`= '$speed' AND `date`='$date' ORDER BY `id` LIMIT 2";
when i run the query in mysql it works fine and even in the query builder window of Dreamweaver MX. However, when i pull the page up in the browser it gives me the error.
-
Jan 19, 2005, 15:34 #11
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
that query looks okay
the problem is likely your php code
Bookmarks