SQL PHP HTML ASP JavaScript articles and free scripts to download
SQL Math Functions

SQL MOD Command

Mod is a math function of MySQL which returns the reminder after a division. We will try to use this function in our query to get different results. Here are some examples.

select mod(100,20) // output is 0
select mod(52,25) //Output is 2
select 24%7 //Output is 3

We can use mod function in our student table
Getting all the records for which id number is even

SELECT * FROM `student` WHERE mod(id,2)=0

Another way we can also write

SELECT * FROM `student` WHERE id%2=0

How many even id numbers are there in our student table

SELECT count(id) as no, name,id FROM `student` group by mod(id,2)

Updating all the records with even number of student id by using concat function

update student set address = concat(name,'_address') where mod(id,2)=0

Be the first to post comment on this article :


Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer