Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




SQL LIMIT Conflict


I'm using Dreamweaver to create a list from a MySQL table, however I want to limit the list using the SQL syntax "1,999" (so that I can start at the second record and go from there.)

However when I load the page on the server I get an error: 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 'LIMIT 0, 5' at line 1

I'm assuming that this must mean that there is some sort of conflict and that Dreamweaver is setting its own LIMIT on the recordset.

Question is how cna I influence the LIMIT that DMX puts on the recordset? It works fine when I take out my LIMIT clause form the query.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Version Conflict
I've created a stored proc using MySQL Administrator Ver 1.1.9 which runs fine in MySQL Query Browser 1.1.20. However, when I use it in a C++ program it gives me the following error:

[MySQL][ODBC 3.51 Driver][mysqld-5.0.22-community-nt]You have an error in your SQL syntax; check the manual that corresponds t
your MySQL server version for the right syntax to use near'{0= call 'GetAllJobDetails2'}at line 1.

The first line in the stored proc is:

CREATE DEFINER=`regan`@`localhost` PROCEDURE `GetAllJobDetails2`()

That is what the MySQL Administrator put in when I created it.

Version Conflict
This works perfectly in v4, but in v3.23 it throws a syntax error. I can't see what it is at all...

SELECT DISTINCT page_system_name
FROM page_data JOIN menu_data ON menu_data.menu_group = page_data.menu_group
WHERE page_hidden = 0
ORDER BY menu_data.menu_group_display_order, page_data.page_display_order

Column Name Conflict
I am trying to use the spatial extensions to mysql. In order to check out the latest I checked out the recommended 5.1.24-rc bk branch and built it. Subsequently I discovered that I can no longer create a table with a column name of range. It worked with the default mysql that comes with Fedora Core 7 which is 5.0.45 but not with 5.1.24-rc version I checked out.

The command is: ALTER TABLE m68_v2 ADD COLUMN range VARCHAR(50);

If I change range in the above to frange it works in both versions.
So is it no longer possible to create a column named range?

UNIQUE And INDEX Key Conflict
In phpMyAdmin, there is a warning displayed under my table stating, "UNIQUE and INDEX keys should not both be set for column `feedlist_id`".

Here's my table structure:

Write Conflict Error
I have a database with access as front end and Mysql as back end. I am
gettting the following 'Write Conflict' Error. when i am on my order
form, This form does has a subform where i enter all the products that
are ordered.

Could any one let me know what could cause this problem. I am the only
one using the database as its still in the build stage Code:

Access ODBC 'write Conflict' SOLVED!
I had this problem where a user would attempt to change a record, and
always get the 'write conflict', and that another user had changed the
record... even though no other users were on the database.

I searched high and low for a solution, to no avail. Yes, I had a
primary key; I had a TIMESTAMP field. I played around with Access'
settings for record locking, no record locking, etc.; I set the MyODBC
setting to "return matching rows". None of these worked.

Here is what I found:

I had a TIMESTAMP field in the MySQL table, NULL = OK. I imported data
from a text file into this table. This text file did not have the
TIMESTAMP field, so all of the records in the MySQL table had a
default timestamp of '00000000000000'.

I wrote a SQL statement that changed this TIMESTAMP '00000000000000'
value to an arbitrary value (for example, '20030910134340').
Everything worked fine.

Using A Limit Clause, But Return The Number Of Rows Of The Query Without The Limit
I have heard of a cool feature that mysql provides a way to return the number of rows of an sql statement that contains a LIMIT as if the LIMIT had not been there.

I search the mysql manual, but could not find anything.

Select Query With Limit Same As No Limit?
I have a question, EXPLAIN on a SELECT query seems to return the same as explain without doing a limit.

Here is a dump from my console:

MySQL 4 And MySQL 5 CURRENT_TIMESTAMP Conflict
I've been locally developing a database in MySQL 5. Now I want to put it on my server. In trying to import it, I have come across the following code which is problematic:

CREATE TABLE `physical_pages` (
`id` int(11) NOT NULL auto_increment,
`filename` text NOT NULL,
`created` timestamp NOT NULL default CURRENT_TIMESTAMP,
`lastmodified` timestamp NOT NULL default 񟍰-00-00 00:00:00',
`languageid` int(11) default NULL,
`readonly` tinyint(1) default Ɔ',
PRIMARY KEY (`id`)
);
It's my understanding that MySQL 4, which is running on my server, does not support the CURRENT_TIMESTAMP part of things. How can I modify that CREATE TABLE query to work?

More generally, is there a guide or automatic solution to moving from MySQL 5 to MySQL 4? I am going to have to install this program I'm writing on a number of servers which run MySQL 4, so would like to not have to grapple with manually editing the database dump every time I develop on my machine and update the MySQL 4 machines.

What Does LIMIT Do?
in MySQL, when I do LIMIT x, how does the database work?

1) Does it pull everything relevant, then only takes the x starting from 0 or.

2) Does it only pull the first x amount out and stops?

I Need A Help About LIMIT
i have 10 rows in a table
i want to select the last 3 rows only
i tried: "select * from table1 order by id desc limit 0,3" it selected rows 10, 9 & 8 but i want it ordered like 8, 9 & 10, what should i do??
i also tried: "select * from table1 order by id asc limit 0,3" but it only selects the first 3 rows

it worked when i used subselect:
select * from (select * from table1 order by id desc limit 0,3) as test order by test.id asc
but my host is using mysql 3.23, which does not accept subselecting..

i also tried: "select * from table1 order by id asc limit count(*)-2,3" but it only gave me an error msg
i even tried: "select * from table1 order by id asc limit 3,-1" but same: error

Limit On A Key
I was wondering if there was a way, in MySQL, in a table definition, to set a "limit" on how big a key can get with auto_increment that's not based on data type.

More specifically, I'd like the key to be limited to 0-63 or 1-64 (the first prefered, but I know auto_increment starts at 1). The smallest integer data type is 255 values or 127 signed.

Basically, I want to be able to store these keys as a flag in a BIGINT which is limited to 64 possible flags. (If there are bigger precise data types, I'd love to know.)

I sifted thru the MySQL manual and found nothing.

Other solutions are welcome.

The requirement is to be able to store 0-* keys in a single column to be compared to a list of keys from other sources, and I think being able to use bitwise comparison is much more efficient than doing a script side cross-reference.

I could have the script manage the key, but if MySQL could do it for me.

LIMIT
how to display the remaining result using LIMIT function

ex. SELECT * FROM tbl1 WHERE title = 'field1' LIMIT 10

now the query will display only 10 retrieved records but what if found 20 records, that is my problem... how to display it.

LIMIT
When I execute the following query without the LIMIT clause, it executes
under 1 second. When I add the LIMIT clause, it takes 10 seconds to
complete. The client table contains 100,000 records. What is going on?

SELECT * FROM clients
WHERE rep_id = 1
AND last_name
LIKE '%au%'
ORDER BY first_name
DESC
LIMIT 0 , 10

Limit?
i saw the following in a mysql query:

$stmt = "SELECT
id,
first_name,
last_name
FROM
persons
LIMIT
0, 3";

in that code, what does "LIMIT" mean, and what does it do?

Limit Sql 4.1.22
error from query:

This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

SELECT * FROM news WHERE news.id NOT IN (SELECT news.id FROM news ORDER BY date DESC LIMIT 15)

If limit is not supported how would i archive this?

Using LIMIT
If I'm querying a table where I know it's going to be a unique answer should I put LIMIT 0,1 . My thinking being that if the record I'm looking for is the 3rd of 250,000 then using LIMIT will stop the query after it's found the record instead of going through the other 249,997 records. Is this right?

$sql = "SELECT * FROM db_sector WHERE sector_x = '" . $x . "' AND sector_y = '" . $y . "' LIMIT 1";
$result = mysql_query($sql);
$sector_id = mysql_result($result, "0", "db_sector.sector_id");

Limit
I'm running a query to get a list of students and the class they belong to. Is there any way I can run a single query to return only 4 students from every class if there are more than 4 in some of them? The students have student ids, so I would want the first 4 student ids.

Using Limit
I am trying to use Limit in a subquery but receive an error
Is there another way to archive the same end result without Limit?
SQL:
SELECT *
FROM news
WHERE news.id NOT IN (SELECT news.id FROM news ORDER BY date DESC LIMIT 15)

Error:
#1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

Limit
I want to make a top 3 lists from a table with a query like this
SELECT points FROM table ORDER BY points LIMIT 0,3

This will of course return a list of the 3 lowest values of points in the table, lets say 1,2,3.

Now to my problem...
If several records in the table has 3 points I want to have all those records returned, lets say 1,2,3,3,3

In MS Access this can be solved by SELECT TOP 3 from.......

LIMIT
If I have a sql statement like this:

Code:

SELECT id FROM `asset` WHERE field = 'value' LIMIT 20 , 40

Is it possible to know how many results there would've been if I hadn't used the LIMIT? Or will I need to do the above query and just count the results first, then apply the LIMIT and run the query again to get my limited set of results?

Limit
Could some explain the "LIMIT" function to me? For example, I have the following Code:

$sql = "SELECT name, bio, headShotFile FROM artists WHERE id='$id' LIMIT 0,1";

I bought a web site from a friend and now I'm picking apart the code and learning.
I've done some surfing, but couldn't find a clear explanation, only uses of it. Yet I want to make sure I fully understand it.

Limit
I am in the process of creating a download script, I am using a code to determine if someone is granted access or not to download the file. I want to set it up so they can only download, say, 250 MB a month worth of renders. And then, have the option for them to purchase an upgrade to their download limit, which will increase the limit for that user only.
I want to use my vBulletin memberlist for this, so I already have a database with the users.
I am a noob with MySQL though, and I am completely stumped. I tried this with PHP but failed?

Using LIMIT 0,1
Let's say I do a check for a duplicate email address in a database by using

SELECT COUNT(*) FROM emails WHERE email='' .$email. ''

Will it be faster (as in end sooner) if LIMIT 0,1 is stuck at the end of that query, or does it not matter?

LIMIT Problem
I am having a problem with this mySQL query:

SELECT * FROM my_table LIMIT 4,10

When I do this query in phpMyAdmin, it works like it should - returning 10 records from row 4. When it is in my code, it always returns 10 records from row 0.

Why would the exact same query work in phpMyAdmin but not in my code?

Joins And Limit Used Together
I have a query, which reads all information from tables.

select se.section_name,pr.*,ph.code from prices pr left join pharmacy ph on pr.pharmacy_id=ph.id left join sections se on pr.section_id=se.id where medication_id=7 order by se.order_id asc, cast(`dosage` as SIGNED) asc, cast(`total_price` as SIGNED) asc

result can be viewed here:
http://www.foreign-drugstores-online...oduct.php?id=7

I need to read only top 5 (total price) for each `dosage`

somekind of: group by `dosage` order by total_price desc limit 5 per group

GroupBy And Limit
I have the following query which I would like to sort by a dateToPull field that is stored in a table called date.

SELECT story.title, story.article, story.deptId, story.authorId, author.author FROM story, author WHERE homePage = 1 AND story.authorId = author.id
My goal for the query is to retrieve all the stories that have not yet reached their respective date to be pulled from the page, after retrieving these stories I then will limit only three to be displayed. My attempts to use and IF statement did not work but I have never used GroupBy. I plan to use the LIMIT function at the end of the statement to display only three stories.

The above query works great, except it does not yet have the function to sort by date. Where do I begin to approach this problem from?

Issue With LIMIT
PHP

SELECT item.itemId, item.itemName, 2 * SUM(bans.bansForAgainst) -
COUNT(bans.bansForAgainst)
AS count, bans.bansForAgainst, bans.bansItemId
FROM item, bans
WHERE item.itemId = bans.bansItemId
GROUP BY bans.bansItemId
ORDER BY item.itemId DESC
LIMIT 0,5

But it's not limiting the output...at all.

Using WHERE Clause With LIMIT
Can I do something like this in MySQL:

LIMIT Query
I have a query that returns all the room numbers in a hotel.  What would be the proper syntax for a query to return one instance of each room.  e.g. i want 1 2 3 4, etc. instead of 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3, etc.

Using LIKE And LIMIT In A Query
Is it possible to use LIKE and LIMIT in a query? I am trying to get search results and limit them.

Ive tried different ways but it doesn't seem to work. I have looked up syntax for both LIKE and LIMIT but cannot find one that includes both.

$query = 'SELECT * FROM table WHERE rows LIKE "%$q%" AND LIMIT 0, 10';
$query = 'SELECT * FROM table WHERE rows LIKE "%$q%", LIMIT 0, 10';
$query = 'SELECT * FROM table WHERE rows LIKE "%$q%" LIMIT 0, 10';

Primary Key Limit
I need to have a long primary key (it sounds strange but...).
Mysql say that it not possible to have a primary key longer than 500 chars (i need 520 chars!!!).
Is it possible to change this limit by set up an option?

LIMIT Statement
I'm kind of new to MySQL but am familiar with other DBs. Currently I'm working with a MySQL4 database and I have a very specific problem which could be easily solved via views.

Problem:
I have as follows -
tbl_cat
-id_cat
-txt_name
...
tbl_prop
-id_prop
-id_cat (fk)
-txt_desc
-txt_type
-txt_default
....
tbl_product
id_prod
txt_ref_name
...
tbl_prod_prop
id_prod_prop
id_prop
txt_hash

OK what is all of this? it's a dynamic product for a shop. How does it work conceptually? We create a product category(tbl_cat) and add properties to it (tbl_prop) such as name, picture, html text, etc...
Finally when we create a product, we determine it's category and fill in each of the properties.
My original idea was to use a view to generate the listing of the products and properties, but mysql4 doesn't have views...
What would be the best aproach? I thought of creating a cache table, where when a product is updated or inserted, I run a script that creates updates a record of a temporary dinamic table. Soething like a false view, updated on demand. Is that as stupid as it sounds?

'Access LIMIT'
Is there a way to specifiy a password with mysqldump? I would like to add a few mysqldump commands to a cron but can't seem to figure out a way to schedual them without direct user input of the password

mysqldump -h mysql.yourdomain.com -u user -p dbname > /home/user/mybackup.sql

LIMIT Problem.
I am having problems with the LIMIT parameter of a MySQL query. The query is displayed below:

$imgtype = $_GET['imgtype'];
$cnt = $_GET['cnt'];

if (!isset($cnt)) {
$cnt = 0;
}

//select proper row in table based on cnt.
$sql = "SELECT * FROM `test` WHERE `imgtype` = '$imgtype'";
$sql .= " LIMIT $cnt, 1";
$result = mysql_query($sql);

$row = mysql_fetch_assoc($result);
$imgid = $row['ImgId'];
$imgname = $row['ImgName'];

The table is populated by Image names, types, and location. As you can see I am grabing all the records by $imgtype, then selecting one at a time based on the $cnt. Every time the page is reloaded the $cnt increments by one, so it should select the next row in the table based on the $imgtype and $cnt.

My problem is that even though I should be selecting only the records with the correct $imgtype. Its not, its selecting all the records in the table, even the ones with a different $imgtype.

Field With No Limit
Is there a field in mysql which there is no limit to how many characters the field can hold?

Getting Other Data After Using LIMIT?
I have a table with a few hundreds records of products information. I
need to retrieve the top 10 records based on the sum of the products
quantity. My query is as below:

Select *, sum(qty) as SUMQTY ,sum(amount) as SUMAMOUNT from tdetail
group by barcode order by SUMQTY desc limit 10;

This query gave me 10 records of products(barcode). My problem is that
i need to have another 2 fields for the percentage calculation(
eg.sum(qty) of product N/total qty , sum(amount)of product N/total
amount.), but i dont know how to get the total qty and total amount.
How do i do that in one query?

Select Limit
I have a list of numbers (i.e. 1 to 175) and I want to do a select statement to
get the highest number. I have tried the limit thing but not getting the right output. Can someone shed some light on this?

LIMIT Clause
I want to be able to use LIMIT to control how many rows from one table are
returned, independent of how many rows there are in a second table that is
joined to the first. Code:

Sort With A Limit
What I need to do is display results that are sorted based on user preference. These results need to be paged to display 25 results per page. Currently I'm using a simple sort and limit. However, as many of you smart folks know, MySQL only sorts the values it finds within the limits as opposed to sorting the whole table and then limiting results.

Max_questions Limit
how to find out the max_questions limit of a database? Also, is there one set by default? I know how to set the max_questions but not how to retreive the value. Presumably to find out this I would need root privilege meaning I would not be able to find out this info on my hosts MySQL DB?

Counting With LIMIT
I'm trying to retrieve the number of records found using an offset (with LIMIT), however I get no results back eg.:

SELECT count(propID) FROM properties WHERE propAvailable=-1 AND propType='s' LIMIT 10,10

Produces:

MySQL returned an empty result set (i.e. zero rows)

However, removing the LIMIT eg:

SELECT count(propID) FROM properties WHERE propAvailable=-1 AND propType='s'

Produces:

count(propID)
38

I don't, though, want a count of all the records. The LIMIT works without the count eg.:

SELECT propID FROM properties WHERE propAvailable=-1 AND propType='s' LIMIT 10,10

Produces

Showing rows 0 - 9 (eg. 10 records)

But I only want the count, not the rows - arggghh!

How can I get back a count of a subset of the data? Is there another way of syntaxing this query?

Perl And 64k Limit
I wrote a perl script that loads a file to a MYSQL server. The sript works well; however it seems that if a file is more than 64k, it truncates it without warning. My MYSQL server has a 16Mb limit. The field type is Blob. Anyone has any suggestios?

LIMIT To Percent?
I have three queries, one to grab the most commented stories (LIMIT 10), one to grab the least commented stories (LIMIT 5), and on to grab the most recent stories (LIMIT 10). I am combining these using UNION to then randomly grab half of the resulting set.

Is there a way to tell MySQL to "LIMIT 50%" or do I have to run it twice, once for the count and once with a limit? So...

(SELECT * FROM blog WHERE...) UNION (SELECT * FROM blog WHERE...) UNION (SELECT * FROM blog WHERE...) ORDER BY RAND() LIMIT 50%

Count And Limit
Is there a way to make one query to the database grabbing the count() and limiting the query to like 10 rows, but have the count() not be limited to those 10 rows?

Reversed Limit
mysql_query("SELECT object_prs FROM $p_tbl WHERE object_id = '56267G' ORDER BY object_datetime DESC LIMIT 3");

How can i SORT ASC and get last found + 2 I want the same result but sorted reversed...

Limit Rows
I got a forum with a table looking like this

ID (int)
name (varchar)
email (varchar)
insert_date (int)
parent (int)
message(longtext)

How do I make the select query so that I only get one row that has a uniqe parent? The parent is the thread-id in the forum and I'm building a search-engine, and when I search in the forum I only want to get one instance of thread, I mean, if it finds the query several times in a single thread, I don't want it to list the thread more than one time anyway, as of now it lists a thread many times because it finds the query several times in it.

Another question:
I got a Q&A table where users have sent in their questions and someone have answered, the table looks like this:

id (int)
date_insert (int)
title (varchar)
message (longtext)
name (varchar)
answered (int)
answerid (int)

only those which have [answered]=1 will be shown cause I don't want to show a unanswered question, the answer is a new post in the same table but the [answered] is 2 there, just to mark it as a answer and not a question. The [answerid] points to the id where the answer is and it's NULL if it is a answer.

I'm making a searchfunktion to this to and I need to search in both question and answer but I only want to list one title per answer/question. As of now it searches in both answer and question and lists em both if it finds the query in both of them but I only want it to list it once. Lets say that I search for "what if", and "what if" is in both the question and answer it will list them both as to results, but I only want one result
ie.
If it finds it in only the question - one result
if it finds it in only the answer - one result
if it finds it in both the answer and the question - still only one result.
that's what I want.
How do I do that?

LIMIT 4 Statement
When I run this LIMIT 4 statement, it only puts out 3 results, but when queried about how many rows it pulls, it claims 4. I'm worried about the one that doesn't print out. (I need that row, too!) Why isn't it putting out 4 rows? Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved