IT Community - Software Programming, Web Development and Technical Support

why limit wont work for updats statement

This is a discussion on why limit wont work for updats statement within the Database Support forums, part of the Web Development category; why we cant use limit in the update statement ?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-06-2007, 05:07 AM
vivekanandan vivekanandan is offline
D-Web Trainee
 
Join Date: Jul 2007
Posts: 41
vivekanandan is on a distinguished road
Default why limit wont work for updats statement

why we cant use limit in the update statement ?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 05:50 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: why limit wont work for updats statement

Hi vivek,

you can use limit function in the update statement but should avoid start and end position within limit, i mean we should not use limit like 'LIMIT 1,2' instead use LIMIT 2. This will update first two rows that
satisfies the condition.

Refer the below given example :

Quote:
Quote:
mysql> select * from e_employee;
+----+---------+--------+---------+--------+---------+
| id | name | salary | address | phone | dept_id |
+----+---------+--------+---------+--------+---------+
| 1 | kumar | 15000 | chennai | 343424 | 10 |
| 2 | ram | 15000 | chennai | 343424 | 10 |
| 3 | arun | 15000 | chennai | 343424 | 20 |
| 4 | karthik | 15000 | chennai | 343424 | 30 |
+----+---------+--------+---------+--------+---------+
4 rows in set (0.00 sec)

mysql> UPDATE e_employee set salary = 20000 where salary = 15000 limit 2;
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> select * from e_employee;
+----+---------+--------+---------+--------+---------+
| id | name | salary | address | phone | dept_id |
+----+---------+--------+---------+--------+---------+
| 1 | kumar | 20000 | chennai | 343424 | 10 |
| 2 | ram | 20000 | chennai | 343424 | 10 |

| 3 | arun | 15000 | chennai | 343424 | 20 |
| 4 | karthik | 15000 | chennai | 343424 | 30 |
+----+---------+--------+---------+--------+---------+
4 rows in set (0.00 sec)
__________________
Keep smiling...

Last edited by priyan : 08-06-2007 at 05:54 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-06-2007, 06:09 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: why limit wont work for updats statement

Hi,

mysql> CREATE TABLE mytable
-> ( id INTEGER AUTO_INCREMENT PRIMARY KEY,
-> name VARCHAR(100) NOT NULL
-> )type=InnoDB;
Query OK, 0 rows affected, 1 warning (0.21 sec)

mysql> INSERT INTO mytable VALUES (1,'Test');
Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO mytable VALUES (2,'CanTest');
Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO mytable VALUES (3,'WillbeTested');
Query OK, 1 row affected (0.02 sec)

mysql> UPDATE mytable SET name = 'Completed' LIMIT 2;
Query OK, 2 rows affected (0.02 sec)
Rows matched: 2 Changed: 2 Warnings: 0

LIMIT works fine with update statement.

Hope this helps..
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit on Sub-folders / Files in Linux bluesky Operating Systems 5 03-31-2008 11:03 PM
Max User Connection, can limit be increased? senraj PHP Programming 2 12-03-2007 01:59 AM
Gsm sim wont give IMSI? jeyaprakash.c Blackberry 0 11-26-2007 06:50 AM
File Upload Size Limit KiruthikaSambandam ASP and ASP.NET Programming 9 09-27-2007 03:16 AM
How do I limit the number of rows I get out of my database sans PHP Programming 1 09-12-2007 12:20 AM


All times are GMT -7. The time now is 05:41 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0