How To Get The Total Number Of Rows With A Query "limit" ?
I would like to paginate the results of a query on several pages. So I use a query with a limit X offset Y to display X results on a page, ok.
But for the first page, I need to run the same query with a count(*) to know how many pages I will get (number total of rows/ X).
The problem is my query is very slow (maybe 5s) because there is much worch to do, and on the first page, I need to run this query twice (not exactly, but ...) so the page is very very slow to load.
My question is : is there a function to get the total number of rows even on a query with "limit" ? Or what could I do else?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Get The Total Number Of Rows With A Query "limit" ?
I would like to paginate the results of a query on several pages. So I use a query with a limit X offset Y to display X results on a page, ok. But for the first page, I need to run the same query with a count(*) to know how many pages I will get (number total of rows/ X). The problem is my query is very slow (maybe 5s) because there is much worch to do, and on the first page, I need to run this query twice (not exactly, but ...) so the page is very very slow to load. My question is : is there a function to get the total number of rows even on a query with "limit" ? Or what could I do else ?
How To Get The Total Number Of Rows With A Query "limit" ?
I would like to paginate the results of a query on several pages. So I use a query with a limit X offset Y to display X results on a page, ok. But for the first page, I need to run the same query with a count(*) to know how many pages I will get (number total of rows/ X). The problem is my query is very slow (maybe 5s) because there is much worch to do, and on the first page, I need to run this query twice (not exactly, but ...) so the page is very very slow to load. My question is : is there a function to get the total number of rows even on a query with "limit" ? Or what could I do else ?
ERROR 1206 (HY000) At Line 41: "The Total Number Of Locks Exceeds The Lock Table Size"
I'm loading a large file into a table, and I get this error: "ERROR 1206 (HY000) at line 41: The total number of locks exceeds the lock table size" I already searched, and the only advice given was to do an explict full-table lock on that table before loading to avoid the row-by-row locks filling up the lock table. Well, I tried that, and it's not helping either. Here's my log:
Rows In T1 Not In Both T2 And T3 (was "Query Help...")
Scenario: 3 Tables Table1: -t1id -t1machine where: t1machine contains: mach01 mach02 mach03 mach04 mach05 mach06 mach07 mach08 mach09 mach10 Table2: -t2id -t2machines where: t2machines contains: mach01,mach03 mach02,mach05 Table3: -t3id -t3machines where: t3machines contains: mach06,mach07 mach08,mach10 Problem: Need to get machine in Table1 where it doesn't exist yet in both table2 and table3... Tried using NOT IN as part of a WHERE clause but doesn't bring result as I intended, in the example I should be getting mach04 and mach09.
Get Total Number Of Results But Still Use LIMIT?
Is there a (better) way to get the toal number of results from a query but still limit them with a LIMIT clause. For example, in a Google search result, it displays 1-100 of 10,000,000 results. Do they hit the database once for results, and again for a total count or is it all in one query?
Compare 2 Tables And Find Rows Which Don't Match (was "Mysql Noob Question")
I have a products table and a products_description table. They both have products_id as primary key. However, products_description table has more products_id keys then the products table. How do i compare the 2 tables and show just the products_id that dont match from products_descripition table? SELECT products.products_id, products_description.products_id FROM products, products_description WHERE products.products_id != products_description.products_id; I tried that query but got some wierd results and also the results gave me 2 columns when I just want one.
Exclude Rows With Same PARENT_ID If FLAG='cat' (was "I Need Some Help")
In this table PARENT_ID and ID are linked. So if a row has 'cat', all other rows that share its PARENT_ID must be excluded from the result. This also includes rows that have ID values equal to those PARENT_IDs that were just excluded. Table below: | ID | PARENT_ID | FLAG | | 1 | 0 | 0 | | 2 | 1 | 0 | | 3 | 1 | cat| | 4 | 0 | 0 | | 5 | 0 | 0 | | 6 | 5 | 0 | | 7 | 0 | cat| So the query should return rows with ID 4,5,6. and exclude the rest I know that i shouldn't be duplicating the values in FLAG, and that i should have another table with a list of flags.. But I don't think i will be able to change the structure of this system(i didn't create it). Below is the query that i came up with, and that works on that small table above. But it doesn't work on the real database. I was wondering if it's because there's a flaw in the query. SELECT *FROM mytestWHERE parent_fid NOT IN (( SELECT GROUP_CONCAT( parent_fid ) FROM mytest WHERE flag = 'cat')) && fid NOT IN (( SELECT GROUP_CONCAT( parent_fid ) FROM mytest WHERE flag = 'cat')) && flag != 'cat'
Omit Rows Where All Three Columns Are Null (was "SQL Help")
I have three fields.....and if one of those 3 fields has a value in it, then I want that row returned. ie: Column 1 Column 2 Column 3 row 1 null value null row 2 value null value row 3 null null value row 4 null null null so the question is.....how do I create a query that will return rows 1,2,3.....and not 4?
Multiple Rows Returned Instead Of One (was "why This Is Happening?")
I have this select statement PHP $select="select video.id, title, description from video, category, maincategory where maincategory.mainid='$selectcategory' AND maincategory.mainid=category.mainid and video.categoryid=category.categoryid and video.title like '%$searchterm%' or video.description like '%$searchterm%' order by dateadded DESC"; if i put car in the searchterm which is the name of a video.title everything works fine and the result is shown only once... whereas if i put blabla in the searchterm which is included in the description of video.description two rows r returned for the same result instead of one.... why???
Can You "Return Rows" In MySQL Administrator?
I'm use to using SQL's Enterprise Manager for going into my DB and making changes. One of the things I like to do is view all the information in a specific table (return all rows). Can this be done with MySQL administrator 1.1.4? I can see the tables listed, but for some reason, I can't access the information within the tables.
Problem Using "limit"
The following statement does not execute. I need to know how to write it properly. select t1.*,t2.* from contact t1, master t2 order by tablekey limit 4478, 10 I would like to retrieve the content from both tables where t1 is the parent table and t2 the child table. They have a commen key field "id". I have tried to add the "where t1.id = t2.id" clause but that did not work either. I am not too skilled using sub-queries or joins. The most important element I need here is the "limit" range.
Searching For Numbers - "close To" Or "approximate"
I would like to know how to search a table for records where a particular field is "close to" a particular number. For instance, let's say I have a table containing students and their most recent test scores. I'd like to see students who scored 7/10. That's easy enough (select * from table where score = 7). I'd also like to run another query to identify other students whose scores are not 7 but "close to" 7. Ie students who scored 6 or 8. As an added bonus, I'd like to be able to do a related search that shows students who scored 7, then shows the other students ordered by how "close" they are to 7. Ie students who scored 6 or 8 are "closest" matches, and students who scored 1 are "furthest". I hope this makes sense! Is there any pre-existing MySQL command that will do this? Or will I have to run separate queries for each value?
REQ: MySQL 4.0 Equivilent Of "DateDiff("m", Date, Now())=1"
I have a query that works in the rest of the SQL world "SELECT invoice.*, invoice.Date FROM invoice WHERE (DateDiff("m", Date, Now())=1);" which will give me all of last month's invoices. However it doesn't work with MySQL 4.0. While "SELECT Invoice.* FROM invoice WHERE (Month(Invoice.Date) = ((Month(Now()))-1))" Is a close substituent, it will blowup in January. Anyone have an equivalent expression for MySQL 4.0?
Create Single Query From Queries On Two Tables (was "Help With Query...")
I read from other thread that query inside loop is not good idea. May I ask some help how can I create a single query to the following code which I use loop. $sql = "SELECT * FROM mytable order by points desc limit 10"; $rec = mysql_query($sql) or die(mysql_error()); $datas = mysql_fetch_array($rec); do{ $sq = "Select * from secondtable where linkid = '$datas[id]'"; $rst = mysql_query($sq) or die(mysql_error()); $rows = mysql_fetch_array($rst); echo "$rows[somefield]"; }while($datas= mysql_fetch_array($rec)); This works perfectly but I want the second query to be out of the loop if there is a way and how.
Grab 'title' From The Table 'forum' Within The Same Query (was "Help With Query")
I have the following query for my vBulletin database: PHP $get_stats_newthreads = $db->query_read(" SELECT thread.forumid, thread.postuserid, thread.postusername, thread.threadid, thread.title, thread.lastpost, thread.forumid, thread.replycount, thread.lastposter, thread.dateline, thread.iconid, thread.views, IF(views<=replycount, replycount+1, views) AS views, thread.visible FROM " . TABLE_PREFIX . "thread AS thread WHERE NOT ISNULL(thread.threadid) AND $weekold<lastpost AND thread.visible!=0 AND (forumid=34 OR forumid=7 OR forumid=8 OR forumid=11 OR forumid=10) ORDER BY rand() DESC LIMIT 5"); and would like to grab 'title' from the table 'forum' where forum.forumid=thread.forumid
Design For Stock Items And Checkin/checkout Process (was "Query Help")
I'm currently in the process of trying to bodge together a simple(ish) stock system to be used on a company intranet but I've ground to a halt with a particular problem. Using a MySQL database I've got tables with 11 fields, including 'Quantity' (self explanatory) and BookOut. Now this BookOut field contains information on the user who has booked out an item including the users name, the date/time etc The problem I have is this. If an item has a quantity of 7 and a user books out 1, then his/her info is stored in BookOut but when another user books out another 1 of said item at a later stage then the previous BookOut info is overwritten. Is there a way in that everytime another item is booked out that a new line is created within a specific field? } if(!sizeof($error)){ $update_SQL = "Update joystick Set BookOut = '" . mysql_real_escape_string($BookOut) . "', PCserial = '" . mysql_real_escape_string($PCserial) . "', Quantity = Quantity - " . $Quantity . ", MachineNo = '" . mysql_real_escape_string($MachineNo) . "', Date = now() WHERE ID = " . $ID; if(! @mysql_query($update_SQL)){ $error[] = "Update SQL failed"; } The above is the query I am currently using. I'm not totally proficient with .php and have already had a lot of help getting this far.
Query To Populate A Calendar (was "Wanted The Experts Opinions (that Means YOU!)")
I am building my first calendar for a client to list All their events on a month to month basis. There are several tables of data that I need to query to populat the calendar from: Events, Committee Meetings, Lectures, and Group Actions. I was wondering: #1) Is it more effecient to query all the tables once and to store the results into an array that I can check as I loop through and output the days for the calendar? #2) OR, is it better to query all the tables for each day as I loop through and construct the calendar ouput? After formulating my question it seems like a no-brainer: That option #1 would be the most effecient, but I still would like to know your opinions. Especially if you have made a calendar before.
What Is Execution Time Of A Query Based On? (was "a Mysql Question")
when selecting data from the database, does the time taken to retrieve it vary from 56k connections to T3 connections? or does it all depends ont he general server speed/amount of connections on the db? im not sure if ive explained that in the best way for people to understand but im sure someone will get what i mean
List All Clients Not Assigned To Current User (was "Query Help Please")
I have two tables like this: *clients -- client_id -- client_name *manage -- user_id (multiple entries possible) -- client_id To assign clients to users there is a entry in the manage table of the user_id and client id. I want to list all the client_ids and client_names that are not assigned to the current user_id say 1.
Unique Combinations Of Model And Make (was "Query Question")
I'm trying to write a query and was wondering if someone could help me formulate it. Here is an example table I'm working with: Table: vehicles Model Make Ford Taurus Ford Taurus Ford F150 Chevy Tahoe Chevy Blazer Chevy Tahoe I want a query that returns all unique combinations of model and make. So the result set should be: Model Make Ford Taurus Ford F150 Chevy Blazer Chevy Tahoe I know how to return distinct values for one variable, but not for two like that. Any help is greatly appreciated.
Adjacent Theater Seats (was "mySQL Query Issue")
Having not been working with more than a simple SELECT * from table query, I am having a few issues when it comes to using more complex queries. I am currently using a query to select seats from a database using the following query: $query1 = mysql_query("SELECT struct.seatid, struct.row, struct.seatnum FROM seats as seat LEFT JOIN structure as struct USING (seatid) WHERE seat.showtimeid=".(int) $_GET['id']." && seat.available = Ƈ' && seat.timelimit < $minutes2 ORDER BY seat.seatid ASC"); For each record that is selected I want to check if either of the seats either side of it are also selected, if not then it is not to be shown. I have added a while loop below the above query and run another query following it (not sure if that makes sense, so I will paste it below!) while($rows = mysql_fetch_assoc($query1)){ $minusseat = $rows[seatid] - 1; $plusseat = $rows[seatid] + 1; $queryminusseat = mysql_query("SELECT * from seats LEFT JOIN structure WHERE seat.showtimeid=".(int) $_GET['id']." && seat.available = Ƈ' && seat.seatid == $minusseat && seat.timelimit < $minutes2"); $num_rows = mysql_num_rows($queryminusseat)or die(mysql_error()); echo "$num_rows"; //if($minusnum > 0){ //echo "$minusseat <b>" . $rows[seatid] ."</b> $plusseat <br/>"; //} else { //echo "<font color=red>$minusseat <b>" . $rows[seatid] ."</b> $plusseat <br/></font>"; //} } The code above is used below the initial query and the following error is being displayed: Quote: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:Program Filesxampphtdocsprojectprototype1 ickets.php on line 154 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE seat.showtimeid=1 && seat.available = Ƈ' && seat.seatid == 1 && seat.time' at line 1
Count Query Causing "excessive Processor Usage"
For the second time in the past 6 months my hosts have shut down my site because it was apparently causing a shared mySQL 5 server to max out at 100% usage. I'm not much a programmer, know even less about mySQL and obviously don't have access to the server from the back end but I'd appreciate any advice as to whether it is my query that is causing the problem: Set rsMail = objConnC.Execute("SELECT * ,(SELECT COUNT(*) FROM comments WHERE comments.submissionID = submissions.submissionID AND comments.commentInclude = 1) as CommentCount FROM submissions WHERE PigeonHole = 'mailbag' AND Status <> 'hold' ORDER BY submissionID DESC LIMIT 20") Apart from two instances, this query has been working fine on a page that receives between 10,000 and 30,000 visits a day. The site is running on Windows and coded in ASP but is calling a separate mySQL server.
Invalid Use Of Group Function (was "Baffled By Query Error")
trying to figure out why I keep getting this error with the following query: SELECT c.account_id,a.name,a.company,SUM(c.agent_product_time) AS mins FROM account a LEFT JOIN calls c ON c.account_id = a.id WHERE c.calldate >= DATE_SUB(NOW(),INTERVAL 14 DAY) AND c.agent_id = 2 AND SUM(c.agent_product_time) >= '500' GROUP BY c.account_id ORDER BY mins ERROR: #1111 - Invalid use of group function
Most Products Flagged In The Past 24 Hours (was "Query Help")
I need a little help setting up the logic behind a query. Here is the situation: I have 2 tables. Product table. Flag table (flagID, productID, date_flagged). Users can flag products. *date_flagged is a INTEGER unix timestamp. I would like to be able to setup a query where I can pull up products that have been flagged the most in the past 24 hours. At first I figured I would COUNT() the flags and GROUP BY productID, but this of course will only give me the most flagged all time, and because of the grouping by productID will not allow me to filter it by date.
Delete Except Latest 2500 Entries (was "help With Query")
I have a table that holds information on activities. For each activity I store the following: ID, When, Description The ID is the key for the table The When column holds the datetime when the activity was added The table gets filled up pretty quickly. I would like to run a query that will delete ALL the entries except for the 2500 latest ones. The When column should be the one to use when deciding which are the 2500 latest activities Can someone show me the most efficient way of doing this?
Count User Comments In Each Category (was "help On A Query")
I would really appreciate if someone could help me out on this one. this are my tables: comments Comment_ID Video_ID Comment_Text Comment_UserID .... video Video_ID Category_ID ..... category Category_ID Category_Name I'm trying to get a user's count of comments for each category, ordered by the number of comments DESC. basically, I want to show the top categories where the user has posted the highest number of comments. so far this query gets me the category name of where the user has posted: PHP $SQLTemp = "SELECT Category_Name FROM category WHERE Category_ID IN ( SELECT DISTINCT ( Category_ID ) FROM video WHERE Video_ID IN ( SELECT DISTINCT ( Video_ID ) FROM comments WHERE Comment_UserID = $id ) )"; THANKS!!
Count Of *unique* Visits By Page For Each Day (was "Need Help With Query")
Using MySQL 4.1 I have a table 'orders' with the following fields: ipaddress pagenum xtime (which is just the yearmonthday) this is the query: SELECT distinct pagenum,ipaddress,xtime,count(pagenum) AS pagenumtotal FROM `orders` group by pagenum,xtime ORDER by xtime, pagenum asc What I am trying to do is return a count of *unique* visits by page for each day. This query returns a count of *all* visits by page for each day, including repeats. So if a visitors hits a certain page on the site 10 times and adds a record 10 times, the count result will include all 10 records in the count. I want this to only count as 1.
Next And Prev DisplayOrder Values (was "Help With MySQL Query")
I have a table 'Album' containing columns 'PageID' and 'DisplayOrder' (both INT). On each page that is displayed I want to have 'previous' and 'next' links to other pages, which are arranged via the DisplayOrder column. At the moment I'm doing this in 2 separate queries: SELECT DisplayOrder FROM Album WHERE PageID = $currentPage $currentNo = [result of last query] SELECT PageID FROM Album WHERE DisplayOrder IN ($currentNo-1, $currentNo+1) Highly simplified but you get the idea. Would it be possible to combine this into one query?
Find All Games A User Has A Top 3 Score In (was "Need Help With A Query")
I am trying to create a query that will go through a scores table for me and find all the games that a user has a top 3 score in. Here are the table that are relevant I think... CREATE TABLE files ( fileid int(11) NOT NULL auto_increment, file text NOT NULL, icon text NOT NULL, filelocation int(1) NOT NULL default Ƈ', iconlocation int(1) NOT NULL default Ƈ', customcode text NOT NULL, title text NOT NULL, description text NOT NULL, keywords text NOT NULL, width int(11) NOT NULL default Ɔ', height int(11) NOT NULL default Ɔ', category int(11) NOT NULL default Ɔ', timesplayed int(11) NOT NULL default Ɔ', status int(1) NOT NULL default Ɔ', filetype int(2) NOT NULL default Ɔ', dateadded date NOT NULL default ��-00-00', rating int(11) NOT NULL default Ɔ', totalvotes int(11) NOT NULL default Ɔ', totalvotepoints int(11) NOT NULL default Ɔ', scores enum(Ɔ',Ƈ') NOT NULL default Ɔ', PRIMARY KEY (fileid) ) TYPE=MyISAM AUTO_INCREMENT=2285 ; CREATE TABLE scores ( scoreid int(11) NOT NULL auto_increment, fileid int(11) NOT NULL default Ɔ', score int(11) NOT NULL default Ɔ', username text NOT NULL, userid int(11) NOT NULL default Ɔ', usercomment text NOT NULL, dateadded date NOT NULL default ��-00-00', PRIMARY KEY (scoreid) ) TYPE=MyISAM AUTO_INCREMENT=16 ; CREATE TABLE users ( userid int(11) NOT NULL auto_increment, username text NOT NULL, password text NOT NULL, email text NOT NULL, status enum(Ƈ',Ɔ') NOT NULL default Ɔ', usergroup int(11) NOT NULL default Ƈ', joined date NOT NULL default ��-00-00', played int(11) NOT NULL default Ɔ', comments int(11) NOT NULL default Ɔ', avatar text NOT NULL, avatar_uploaded enum(Ƈ',Ɔ') NOT NULL default Ɔ', location text NOT NULL, website text NOT NULL, gender int(1) NOT NULL default Ɔ', favourite int(11) NOT NULL default Ɔ', receiveemails enum(Ƈ',Ɔ') NOT NULL default Ƈ', newpm enum(Ƈ',Ɔ') NOT NULL default Ɔ', confirmation text NOT NULL, PRIMARY KEY (userid) ) TYPE=MyISAM AUTO_INCREMENT=8 ; ( Basically the query would need to search through the scores table to find if the specified user $userid has the top 3 (by top 3 i mean 1st, 2nd, or 3rd highest score) scores of any game in the scores table. The end resukt would be a list that contained the fileid of the game the user has a top 3 score in, the actual score, and the position (1, 2, or 3) Im not sure if I am even explaining this right cause im kind of tired. I am a novice MYSQL user but this just has me stumped
Script To Change All Columns (was "mysql Query")
I have a table. I need to make some changes like change column name, change int() to var() etc. So I want to write a query that alter all the columns of the table then the data which were in the database before can be reinserted.
Models Where The Years Overlap (was "Query Help Needed")
I'm trying to formulate a query for the following example: Table: model_by_year model start_year end_year model_1 2001 2004 model_1 2003 2004 model_2 2000 2005 model_2 1998 1999 model_3 1998 2003 model_3 2002 2006 I want a query that will return all like models where the years overlap. In other words, I'd want to return model_1 and model_3, but not model_2.
"Lost Connection To MySQL Server During Query"
Bog standard SuSE 8.2 Linux install. I have installed mySQL (off the SuSE 8.2 distro CDs). I can connect locally, e.g: bealzebub> mysql -u root -p mysql -h localhost ....logs me in just fine. However, this: bealzebub> mysql -u root -p mysql -h bealzebub ....causes the connection to fail with: "ERROR 2013: Lost connection to MySQL server during query". Its the same if I try to log in from another machine.
"Lost Connection To MySQL Server During Query"
Hi, I wonder if anyone can help me with this. Bog standard SuSE 8.2 Linux install. I have installed mySQL (off the SuSE 8.2 distro CDs). I can connect locally, e.g: bealzebub> mysql -u root -p mysql -h localhost ....logs me in just fine. However, this: bealzebub> mysql -u root -p mysql -h bealzebub ....causes the connection to fail with: "ERROR 2013: Lost connection to MySQL server during query". Its the same if I try to log in from another machine. Anyone?
Total Number Of Rows Affected
in Mysql Control Center, how can I modify the Total Number of Rows Affected in a query?? in fact I want to disply all the records of the table but I get only 1000 rows, is it possible to do that and how?
DB Rows Just "disappearing"
I've been getting complaints lately that entries to a database are just "disappearing", they are entered via PHP, and the system works fine. Only certain people have access to the PHP interface and even of those selected people only 1 or 2 people have the 'power' to delete a row. But I've been told that after adding an entry and seeing that it is deffinitely there, they come back later to find it's gone and nobody has deleted it. It happens very rarely, there are thousands of database entries but this sort of disappearance has only happened a handful of times. Can rows just go missing? How? If it turns out that I can't find the source of the problem then I'll have to just try to retrieve these missing rows everytime one disappears. Is there a way to retrieve 'deleted' rows from MySQL? One has gone missing today so I'd be glad to find out how I could get it back.
"Consuming" Rows - Best Way To Do It?
One part of my application generates rows (think of them as to-do items) in a table. Periodically, an independently-running part of the application "consumes" those rows: after retrieving the rows and acting on them, the rows should be deleted. However, during this "consumption" processing, the first part of the application might add more rows to the table. Can anyone suggest a clean and efficient way to implement this model in MySQL, minimizing the number of queries? I'd prefer not to DELETE each row as it's handled -- rather, I'd like to drop them "in bulk" when processing is through. If I've consumed all the rows, a simple TRUNCATE TABLE would probably be quick, but I'm not sure how my "consumer" would be able to ensure that no additional rows had been added while it was doing its processing, and I don't want to lock the table during the entire process. I could also add an AUTO_INCREMENT ID field to each row, keep track of the highest one I processed, and DELETE FROM table WHERE ID < highestid... not sure if this is an appropriate approach either.
Value "000" Stored As "0" In Text Field?
I've managed to import my data from a CSV using SQLyog Enterprise, however, I have a problem with the table storing the text value "000", MySQL truncates it to "0", unfortunately, I need the value to be stored as "000", does anyone know of any way that I can force the field to store all the characters, rather than treating it as a number? Surely a text field should treat any numbers stored within it as text?
Return A "true" Or "false"
i wanna do a "select", where if the script finds any matches, i dont wanna know about them. Instead, i just want it to return a a value: true (1) ou false (0). ie.: $sth = $dbh->prepare("SELECT * FROM maps WHERE name='algo' LIMIT 1"); $sth->execute(); if (match is true) { print "True Match. A match was found"; } else { print "False Match. No matches were found."; }
"Group By" Forgets "Order By"
I'm trying to build a simple RSS reader for a client and am running into some serious problems with the GROUP BY in MySQL. Basically I have two tables: one that holds all the entries and one that holds all the feeds. Then what I can do is say: [MYSQL]SELECT * FROM entries WHERE feed_id='13' ORDER BY date DESC[/MYSQL] That will select all the entries that belong to feed #13. This is fine, but what I'm doing now is building a library that will display the feed_id with the latest entry with that id. So I would think it would be something like the following: [MYSQL]SELECT * FROM entries GROUP BY feed_id ORDER BY date DESC[/MYSQL] That should get me the single latest entry from each feed_id. However it's forgetting the ORDER BY clause all together and seemingly ordering it by the auto-incrememnt value in the entries field.
Return Only 3 Photos From 3 Specified Galleries In One Query (was "Is It Possible?")
Let me start from the beginning.... I have a table that lists photo details, with a foreign key to link them to a gallery. Lets say I have 20 photos altogether and 4 galleries, (for simplicity sake, 5 photos per gallery). My question is: Is it possible to query the table to get it to return only 3 photos from 3 specified galleries in one query? (So returning 9 photos altogether, 3 from each gallery) Rather than querying the table 3 times with a limit of 3 and merging the results.
Want Only One Record Returned Per Post_id (was "Help With Query")
I can't figure out how to do this query. Help would be muchly appreciated! I want to get the DISTINCT(post.post_id) but not sure how to do this. Here is the query I have thus far but it's returning two records each with the same post_id but different cat_id's. SELECT post.post_id, auth_alias, pc.cat_id, post_heading, DATE_FORMAT(post_created, '%M %d, %Y'), post_body FROM posting post LEFT OUTER JOIN post_cats pc ON post.post_id = pc.post_id WHERE post_status = Ƈ' ORDER BY post.post_created DESC LIMIT 0,5
|