Limiting Query Time
Is it possible to limit the query time in MySQL (3.x or 4.0)? For
example, I'd like to have any query that takes more than a specified
number of seconds just quit automatically. Seems dumb, but on a web
site, nobody is going to wait minutes for a query to return so they
refresh anyway. So on a busy server, MySQL ends up with several queries
running that all take a long time to finish which compound to make it
even slower. A simple time limit would solve the problem. Yes, I know
that the queries should take less time, but again, on a busy server,
sometimes the longer queries do take a long time (10 minutes or more)
to complete.
View Complete Forum Thread with Replies
Related Forum Messages:
Limiting Results In Query Question
I've got a SQL query which i want to return one result from each development in the database. The result i want to be returned is the first image in the database related to a development. There are currently two developments in my database however all the images that are stored in the database are returned and not one per development. QUERY: select development_images.development_id, developments.title, developments.description, development_images.url, development_images.image_title from developments, development_images WHERE developments.id = development_images.development_id order by developments.id DESC LINK: http://demo2.pixel-room.net/developm...dex.php?page=1
View Replies !
Grouping For A Query And Limiting Returned Data In Order Of IN()
I'm trying to pull some data from the database in which it's supposed to return 3 rows from each f.forumid in the order in which i have the forumids, however it seems to be returning all the data from the table, what am i doing wrong? PHP Code: SELECT t.threadid, t.title, t.lastpost, t.forumid, t.open, t.replycount, t.postusername, t.postuserid, t.lastposter, t.dateline, t.views, t.firstpostid, f.title AS forumtitle, p.pagetext AS preview FROM thread t INNER JOIN forum f ON (t.forumid = f.forumid) AND t.visible = 1 LEFT JOIN post p ON(p.postid = t.firstpostid) WHERE t.forumid IN(200,250,2,30,15,60,70,90) GROUP BY f.title, t.title HAVING COUNT(*) <= 3 ORDER BY f.forumid, t.dateline DESC
View Replies !
Get Query Time Query Time Using PHP
I just want to ask, how to get query time like this one: SELECT f_name, l_name from employee_data where f_name = 'John'; +--------+------------+ | f_name | l_name | +--------+------------+ | John | Hagan | | John | MacFarland | +--------+------------+ 2 rows in set (0.00 sec) <- This Time <-- Maybe some instruction using PHP?
View Replies !
Time Query - Please Help?
I’m completely baffled by a query that I thought I had working yesterday, but I can’t get it working today. Here’s the screnario: I’m publishing a story to the web and I don’t won’t it to be published live until: -The current date (type: date) is less or equal to now -The current time (type: time) is less or equal to now So here’s my query: select * from cms_stories WHERE section = 'news' AND published_web_date <= NOW() OR published_web_date IS NULL AND (published_web_time <= NOW() OR published_web_time IS NULL) ORDER BY story_id DESC LIMIT 1 Now the query works for the published_web_date, but not for the published_web_time. It seems to ignore that as you can see from the screenshot returned below from that query.
View Replies !
Add Time Using A Select Query
Hello, how can I add, say, 2 hrs from a time in a database using a select query. I have searched the forums but cannot find an answer. Is it possible PHP Code: select date, `time` as timetime , time_format(`time','%l:%i %p') as Printtime, client, address from..........
View Replies !
Exceeded Run Time Query
I made a application in PHP, I have a table "control1" and this table have 85000 registries and Size is 200 MB, so when I try do a query in PHP, I have a error "exceeded run time", I changed the time but is the same, and after I connected by console, and I could see that the query take 14 minutes. Here my sql: $sql_filtro="SELECT COUNT(*) nFilas FROM control1 WHERE MATCH (contenido) AGAINST ('$q')";
View Replies !
How To Get Time Execution Of A Query?
Do you know how to get the time that a query executes? Is there a formula on how to get it? Example: Note: I have 5000 data in the table cars $result = mysql_query("Select * from cars"); Question: How to get time of executing the query above?
View Replies !
How To Get Query Execution Time
How to get query execution time in "mysqlquery.log" files I am using: Linux 7.3 mysql 4.1 How to display the query execution time for each and every query in log files. i have configured "slow-log-query" and "mysqlquery.log" in "my.cnf" is pasted below. log = /var/lib/mysql/mysqlquery.log log-slow-queries = /var/lib/mysql/slowquery.log long-query-time = 0 slow-launch-time = 1 then i can get a output in "mysqlquery.log" like, 070830 9:24:29 2 Connect root@localhost on 2 Init DB jbdatabase 2 Query select count(*) from vacancy1_table 2 Query select category,listcategory from category_t able order by category 2 Quit but i need to display the "timetaken of each end every executed query" along with the query in the above logfile like, E.g:select category,listcategory from category_table order by category(0.03 secs).
View Replies !
Execute Time Of A Query
I'm running a SELECT * query on a table with over 3,000 rows. I need to know the execute time on the query. PHPMyAdmin shows it to me, but because they automatically add a LIMIT 0, 30 I suspect the time is only for those 30 records. It also has a feature to prevent web server timeouts that prevents me from setting the LIMIT to 0, 3100. BTW, I'm programming in PHP. Does the time to run the query get automatically passed when PHP sends the query to MySQL? <? PHP $Query = "select * from my_table where 1"; $Result = MYSQL_QUERY($Query); ?>
View Replies !
Last Query Execution Time
Is there a way to retreive the elapsed time for the prevously executed query? Alternatively, Is there a way to query the current time in fractions of a second? I am attempting to use a stored procedure to execute and track the time it takes to run some queries and other commands. The logic of the stored proc would go something like this.....
View Replies !
Using Time Functions Within A Query
I'm currently working on a script that searches through a database of restauarant information. One of the things it does is allow the user to search only for restaurants that are open at the time of the search, however i get errors when trying to implement this. Here is the query im using:
View Replies !
Take Long Time To Run A Query!
I have a webserver that I just use for a webapplication. PHP, Apache and MySQL is installed on the server. The size of MySQL database is 10 GB. End inn it is millions of rows. I wonder where I search what is the normail time the data to return? In my case it takes from 20 sec to 2 min to run a query!
View Replies !
Time Query Question
I'm trying to pull dates from a db that are newer than 6 months old. I've been testing with 1 day, since there's nothing in the db that's older than 6 months. query PHP $DATEsql = "SELECT DISTINCT DATE_FORMAT(time_in, '%m/%e/%Y') as time "; $DATEsql .="FROM login "; $DATEaql .="WHERE time_in > CURDATE() - INTERVAL 1 DAY "; $DATEsql .="ORDER BY time DESC "; that is giving me the same results as PHP $DATEsql = "SELECT DISTINCT DATE_FORMAT(time_in, '%m/%e/%Y') as time "; $DATEsql .="FROM login "; $DATEaql .="WHERE time_in < CURDATE() - INTERVAL 1 DAY "; $DATEsql .="ORDER BY time DESC "; This is what I'm interpreting as what I need to do according to the MySql manual.
View Replies !
Query Log With Execution Time?
I have developed a big property portal web site and have probably written about 1000 different SQL queries in the process (OK, maybe only 500 or so) but a lot. The site is now gaining popularity and although it is on a dedicated server I want to make sure that everything is running smoothly. I have optimised several tables with indexes etc. and have sped up certain tasks, but would like to know if there are any other queries that take too long and should be optimised. Is there a way to log all queries together with the time it took to execute the query? Is this already logged and if so - where is it?
View Replies !
Query Execution Time In PHP Script
I am interested in displaying the query execution time as mysql does from the console, but using php. I've looked everywhere for this and can't find anything. Does anyone know how to display this information to the browser via php? The information must be there since the console provides it. I checked the php function mysql_info(), but that only shows records, duplicates, deleted, matches, changed, warnings, etc. Didnt see any specific php function for getting execution time.
View Replies !
Time Zone For Query Browser?
My server time is set to CST. phpMYSQLadmin shows CST. The website that the information is stored on is CST. When I do a query from MySQL Browser, it's providing information back in GMT. Does the browser undo timezone? It makes since on a corporate level, so that the time is always being pulled up correctly. So, my question is. If all my servers and sites are all set to CST, do I still need to do queries with a time zone change in it, CST?
View Replies !
TIMESTAMP :: Query By Time And Date
I have a field in my table that holds a timestamp. Below is a pseudo-query to describe what I would like to do. SELECT * FROM `mytable` WHERE `saved_date` <= `6/24/05 10:22:34 AM` `saved_date` is the field holding a TIMESTAMP. If anyone could give me the query that would actually do what I am trying to do above,
View Replies !
Query Execution Time & Mysql_stat
I am using mysql for my shopping site,Performance of site very slow then I used mysql_stat php function to find out how many slow queries,it shows 20. Now my question is any function in mysql(or)PHP to show 20 slow queries.
View Replies !
Average Query Execute Time???
I have a query taking about 4 sec that gets only 18 records.. That's not good. What can I do to speen up my Query? <CFQUERY DATASOURCE="#datasource#" NAME="qry_job_search"> SELECT DISTINCT (t1.JobPostId), t1.Actionlkp, t1.Date, tbl_job_posting.*, tbl_job_post_requirements.*, tbl_employer_info.*, tbl_employer_url.*, tblkp_employment_type.*, tblkp_education_exp_lvl.*, tblkp_salary_range.*, tblkp_employment_exp_lvl.*, tbl_job_post_location.*, tbl_job_post_job_categories.JobCat, tblkp_countries.*, tblkp_prefectures.* FROM tbl_job_post_history AS t1 JOIN tbl_job_post_location ON tbl_job_post_location.JobPostID = t1.JobPostID JOIN tblkp_countries ON tbl_job_post_location.CC1 = tblkp_countries.CC1 JOIN tblkp_prefectures ON tbl_job_post_location.CC1 = tblkp_prefectures.CC1 AND tbl_job_post_location.PrefectureID = tblkp_prefectures.ADM1 LEFT JOIN tbl_job_post_requirements ON tbl_job_post_requirements.JobPostID = t1.JobPostID LEFT OUTER JOIN tbl_job_post_job_categories ON tbl_job_post_job_categories.JobPostID = t1.JobPostID JOIN tbl_job_posting ON tbl_job_posting.JobPostID = t1.JobPostID JOIN tbl_employer_info ON tbl_employer_info.UserID = tbl_job_posting.UserID LEFT JOIN tbl_employer_url ON tbl_employer_url.EmployerID = tbl_employer_info.EmployerID JOIN tblkp_employment_type ON tblkp_employment_type.ID = tbl_job_posting.EmploymentType JOIN tblkp_education_exp_lvl ON tblkp_education_exp_lvl.ID = tbl_job_posting.EducationExpType JOIN tblkp_salary_range ON tblkp_salary_range.ID = tbl_job_posting.Salarylkp JOIN tblkp_employment_exp_lvl ON tblkp_employment_exp_lvl.ID = tbl_job_posting.EmploymentExpType WHERE t1.JobPostId NOT IN ( SELECT DISTINCT (JobPostId) FROM tbl_job_post_history WHERE Actionlkp =4 AND date = ( SELECT MAX( date ) FROM tbl_job_post_history WHERE JobPostId = t1.JobPostId ) AND JobPostID = t1.JobPostID ) AND HistID = ( SELECT MAX( HistID ) FROM tbl_job_post_history WHERE JobPostID = t1.JobPostId AND Actionlkp =1 ) AND Date >= ( curdate( ) - INTERVAL 30 DAY ) <CFIF SESSION.COUNTRY_A NEQ "" AND SESSION.PREFECTURE_A EQ 0 AND SESSION.CITY_A EQ ""> AND tbl_job_post_location.CC1 = '#SESSION.COUNTRY_A#' <CFELSEIF (SESSION.COUNTRY_A NEQ "" AND SESSION.PREFECTURE_A NEQ 0 AND SESSION.CITY_A EQ "") OR FORM.PREFECTURE NEQ 0> AND tbl_job_post_location.CC1 = '#SESSION.COUNTRY_A#' AND tbl_job_post_location.PrefectureID = '#SESSION.PREFECTURE_A#' <CFELSEIF SESSION.COUNTRY_A NEQ "" AND SESSION.PREFECTURE_A NEQ 0 AND SESSION.CITY_A NEQ ""> AND tbl_job_post_location.CC1 = '#SESSION.COUNTRY_A#' AND tbl_job_post_location.PrefectureID = '#SESSION.PREFECTURE_A#' AND tbl_job_post_location.PostCity LIKE '%#SESSION.CITY_A#%' </CFIF> <CFIF (SESSION.CATEGORY_A NEQ 1) OR FORM.CATEGORY NEQ ""> AND tbl_job_post_job_categories.JobCat = '#SESSION.CATEGORY_A#' </CFIF> <CFIF (SESSION.KEYWORD NEQ "") OR FORM.KEYWORD NEQ ""> AND t1.Actionlkp = 1 AND (tbl_job_posting.JobTitle LIKE '%#session.Keyword#%' OR tbl_job_posting.JobDescription LIKE '%#session.Keyword#%' OR tbl_job_post_requirements.JobRequirements LIKE '%#session.Keyword#%') <CFIF SESSION.KEYWORD NEQ "" AND SESSION.PGV NEQ "brief"> <CFSET SESSION.PGV = "detailed"> </CFIF> </CFIF> <CFIF SESSION.EMP_TYPE_A NEQ 1> AND tbl_job_posting.EmploymentType = '#SESSION.EMP_TYPE_A#' </CFIF> <CFIF SESSION.EXP_LVL_A NEQ 1> AND tbl_job_posting.EmploymentExpType = '#SESSION.EXP_LVL_A#' </CFIF> <CFIF session.SRT EQ "D"> ORDER BY Date DESC <CFELSEIF session.SRT EQ "C"> ORDER BY tbl_employer_info.CompanyName <CFELSEIF session.SRT EQ "L"> <CFIF form.country NEQ 0> <CFIF form.prefecture NEQ 0> <CFIF form.city NEQ 0> ORDER BY tbl_job_post_location.PostCity </CFIF> <CFELSE> ORDER BY tblkp_prefectures.FullNameS, tbl_job_post_location.PostCity </CFIF> <CFELSE> ORDER BY tblkp_countries.CC1, tblkp_prefectures.FullNameS, tbl_job_post_location.PostCity </CFIF> <CFELSEIF session.SRT EQ "T"> ORDER BY tbl_job_posting.JobTitle </CFIF> </CFQUERY> Can anybody see a shortcut to get the same results??
View Replies !
Comparing Dates Y, M, D , Time In Sql Query
ok.. ive finally got my nice little calender setup to output my dates now how do i query my database for example ive got 2 variables $startdate = 2006-1-1 00:00:01 $enddate = 2006-1-1 23:59:59 these represent the 1st and last second of the first of january 2006 i have a cell in my table (table called challenges) ( cell called time) that contains a date in the same format for each entry how do i get all the entries between the start time and the end time.. can i use less than < and more than > as these are not really integar values the column type is datetime but there is also another column of type datetime
View Replies !
Query Takes A Long Time
On my site I have a query that searches through 1,7 million. The php-file with the query takes a bit of time to load. Is it possible to show some sort of progress-bar during this time?
View Replies !
Any Tips For Improving This Query Time?
Is there anything I can do to improve execution time for this query? mysql> SELECT webpageUrl, webpageName, COUNT(*) AS `count` FROM _1_log GROUP BY webpageUrl ORDER BY `count` DESC LIMIT 5; +---------------------------------------------------------+---------------------------------------------------------------+-------+ | webpageUrl | webpageName | count | +---------------------------------------------------------+---------------------------------------------------------------+-------+ | http://www.w3counter.com/ | W3Counter - Free Web Counter, Web Stats, Live Analytics | 2490 | | http://www.w3counter.com/stats/visitors/4071/day/1000/0 | Visitors Overview - www.pitbullmortgageschool.com/ | 1496 | | http://www.w3counter.com/stats/4071/v_daily | W3Counter - Visitors by Date - www.pitbullmortgageschool.com/ | 1130 | | http://www.w3counter.com/stats/ | Your Websites | 1124 | | http://www.w3counter.com/stats/websites | W3Counter - Websites | 800 | +---------------------------------------------------------+---------------------------------------------------------------+-------+ 5 rows in set (0.88 sec) mysql> explain SELECT webpageUrl, webpageName, COUNT(*) AS `count` FROM _1_log GROUP BY webpageUrl ORDER BY `count` DESC LIMIT 5; +----+-------------+--------+------+---------------+------+---------+------+-------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------+------+---------------+------+---------+------+-------+---------------------------------+ | 1 | SIMPLE | _1_log | ALL | NULL | NULL | NULL | NULL | 29422 | Using temporary; Using filesort | +----+-------------+--------+------+---------------+------+---------+------+-------+---------------------------------+ 1 row in set (0.00 sec) It averages 0.5-3 seconds throughout the day (it's run often enough that it shows up in my slow query log multiple times an hour for exceeding 1 second). Adding a partial index on webpageUrl doesn't affect anything, and URLs can be quite long. Is there anything I can do to speed up that query? The table is updated too often to maintain separate url/count tables -- can't spare the resources.
View Replies !
Looking For Query To Get Time Of Last Column Count Increase
Code: id | time | units ------------------------------------ 1 | 2009-01-06 06:52:32 | 50 1 | 2009-01-02 16:45:23 | 50 1 | 2009-01-02 09:12:16 | 40 1 | 2009-01-01 12:06:00 | 35 2 | 2009-01-04 14:52:30 | 259 2 | 2009-01-04 04:52:30 | 258 2 | 2009-01-03 18:00:01 | 258 I need to write a query that will, for each unique id, return the last time there was an increase in the "units" column. So for this data set, I want to see: Code: id | time ------------------------------------ 1 | 2009-01-02 16:45:23 2 | 2009-01-04 14:52:30
View Replies !
Time Out Message When Query Large Tables
I'm trying to get data from 6 large tables but the volume of data in each table is too large and even select * from one of them make the system stop. I have afew questions: 1-what can I do to avoid the system stop or time out message? 2- To use several tabels infomation should I use 'View' command or can I use other methods? 3-I need to create a new table and insert the result from query in it. If I use the "view" can I insert the result of the view in a table? (I use postgresql).
View Replies !
Query To Display A Record By Recent Time
Many users uploaded their files to my mysql table through php script, my table having the details of uploading time, file name, & uploader name. i need to find the recent uploaded file for all uploaders. i tried with this query, select file_name,uploded_by,MAX(date_time) from upload group by uploded_by; it is giving the recent time, but it is not giving the latest file, it is showing first uploaded file.
View Replies !
Effect Of Increased Users On Query Time - Rec Specs
I have just started my first big project and I am having trouble predicting the system specs that will be required. At present during trials the site has around 15 users, although this will go to 350 when it is launched. Most of the pages execution time should not scale with the increase in users but there are a few report pages which calculate and order the information entered by the users. Measuring the page on my development machine (Duron 1.2, 768MB PC133, WinXP, running apache 1.3.22, mysql 4.0.15and php4.3.4)... One page I am currently getting 0.2-0.3 seconds. It uses phplib templates and it executes 9 queries at present, 1 of which I predict will scale. It calculates the mean, standard deviation and total of around 90 measures using results from 15 users. I do have a few nightmare pages for the regular users which execute 150+ queries (mixture of selects and updates). Can anyone predict what will happen with 300+ users? I am thinking max load being 20 regular users logged in with 2 users viewing reports. The machine I am currently looking at is P4 2.4, 512DDR with Linux. Will this be suitable?
View Replies !
Truncated Time Values Using TIMEDIFF With ORDER BY Query
I'm using the following query: SELECT glider, timestamp, TIMEDIFF(timestamp, UTC_TIMESTAMP()) AS last_contact FROM surfacings INNER JOIN (SELECT MAX(timestamp) AS most_recent FROM surfacings GROUP BY glider) AS tmp WHERE surfacings.timestamp = tmp.most_recent; to calculate the amount of time that has elapsed since the last inserted timestamp for each glider. Everything works fine: ....
View Replies !
Time Based Reservation System - Only 1 Query Should Succeed
a user can select a time they want and submit the page * The code selects all the bookings for a range of time. * It then counts how many concurrent bookings there are for each hour. * If there's less than the total (4) it inserts another row ( the user's requested booking ) into the booking table. We also notify people if there has been a cancellation This has led to a situation where a few different people are trying to book the same session at the same time, and succeeding! We've ended up with 5 sessions booked In the course of 2 page requests this seems to happen: User1 - submits their booking site selects to see if there's availability ( there is!) User2 - submits their booking site selects to see if there's availability ( there still is!) site inserts User1's booking site inserts User2's booking
View Replies !
Limiting
I have a products table which apart from other things has a column called manufacturer. I want to run a query that returns x number of products PER manufacturer for each manufacturer that matches some criteria. table::products -------- id name cost stock manufacturer I can only figure out how to limit it to 1, eg "select manufacturer, name from products where manufacturer like 'A%' group by manufacturer order by manufacturer, name" which will return something like this Code:
View Replies !
LIMITING Records
Query 1 : SELECT * FROM TABLE_A, TABLE_B, TABLE_C LIMIT 10 WHERE TABLE_A.ID = TABLE_B.ID AND TABLE_B.ID = TABLE_C.ID Query 2: SELECT * FROM TableC INNER JOIN (SELECT * FROM TableA INNER JOIN TableB ON ID) RS1 ON ID LIMIT 10 I'm currently using mysql standard v4.1.7. Whenever i run both queries (see above), it generates an error message, which is 'check version....' Could somebody pls tell me what's wrong with my syntax?
View Replies !
Limiting Access
I'm currently making a Visual Basic application that, when run, presents the user with a username and password field. Their account corresponds to one that is from a forum, the database of which is in a remote location to where the application is running from. If I create a new user to access MySQL, how do I allow any IP address to connect to one specific database, while still only allowing all other users to connect from "localhost"?
View Replies !
Limiting Results
I have two tables one with three rows one with several. I am left joining the second table with the first one based on shared data (a id number that matches in both tables). I run mysql_fetch_array until I have read all the data but heres the problem. Each row in table one is being returned more than once as it matches more than one row in table 2. For each row in table 1 I want to get only the first matching row in table 2. Does that make ANY sense?
View Replies !
Limiting Search
i only want to records on this page were the value lot has been duplicated within the colum lot. can anyone help me here please. $query = "SELECT * FROM main GROUP BY lot ORDER BY time, part LIMIT $start, $display";
View Replies !
Limiting Databases
I am recently moving my server from a VPS Linux (WHM/Cpanel) box to a Windows 2003 box. I have gotten PHP and MySQL installed (can login no probs with phpmyadmin) but what I wondering is if there is a way to create users so that when they login to phpmyadmin they can only see the database's they create like its done on my Cpanel machine. Right now I can create new users and such, but they can see all the databases that are already there.
View Replies !
Limiting Inner Joins
This has been bothering me and the relation isn't typical of the other expressions I've had to build. I have a table of 250 records that I'm returning ie. SELECT B.ID, B.Title, B.Owner FROM blogs AS B WHERE B.Status = 0 I need to return not only the blog name but the latest post they've made on their account. So what I did was used: SELECT B.ID, B.Title, B.Owner FROM blogs AS B INNER JOIN archives AS A ON B.ID = A.BlogID WHERE B.Status = 0 But when I do this it returns each record in archive with the relevent blog information. What I would like is for it to determine the latest ID insert on the blog. So if he has posts IDs such as 1010, 1050, 2063 and 2075 then it will return the blog information and the results of record 2075 in the archives table. I've tried a couple ways so far but each fails, I think what I want to do is somewhat limit the return on the inner join...sort of like add a WHERE clause unto the clause. I would have done this with a stored proc. or a view but I'm using MySQL 4 and I want to keep the querying function in my code for now. Not sure if that makes sense to the experts, if my problem isn't clear let me know I'll explain it further.
View Replies !
Limiting Downloads
I have the task at hand of limiting the number of downloads that a registered user has access to on a site I am helping out with. I have a way to count the downloads by a user, but cannot seem to find the way to limit them. Does anyone know a tip for this or perhaps a link to some kind of tutorial? I am fairly novice with MySQL.
View Replies !
Complex Limiting In A Join
How do I limit a certain amount of records from a join, ie (quick and idealist ***not for accuracy***) SELECT * FROM players p, games g LIMIT **first 5 games for each player, but return all players*** is this possible without a subquery?
View Replies !
Limiting Number Of Posts
i have a penpal page where registered users post messages to each other. every now and then i get spam/ advertisers post between 500 and 2000 messages to users (using scripts). is there any way where i can set / add a script so that system check how many email a user post per day or so and block him from posting with a message saying "you reached your daily limit or so ..". or is it better to use capcha ? somebody is using some sort of automated script to fill out forms.
View Replies !
Limiting Results Returned
can someone show the correct sql to query a db so it will return say ...the first 50 records...then the next 50 records and so on? I have tried different combination of LIMIT x,x with no success...
View Replies !
Extending The Limiting Of Results
I have a table which is updated continuously and has over 2 million records in it, lets call it table A. The records have a "category" field and also a "date" field. Is there a way to get the most recent 10 records for each category in a single query? I know I can use "ORDER BY date DESC LIMIT 10" to get the 10 most recent records from the table, but I would like to extend this to get the most recent 10 for each category. I guess it would be the equivalent of (SELECT * FROM A WHERE category='cat1' ORDER BY date DESC LIMIT 10) UNION (SELECT * FROM A WHERE category='cat2' ORDER BY date DESC LIMIT 10), etc... It seems like there must be an easier way using a JOIN or something?
View Replies !
|