Many times we need to retrieve the last record in each group while working with database. Here group is set of those rows which have a identical column value.
You can use a ‘GROUP BY‘ to obtain the result but query with ‘LEFT JOIN‘ performs far better.
Category » MySQL
DATETIME or TIMESTAMP – Comparison
MySQL has DATETIME and TIMESTAMP fields to store date & time in MySQL database. There are some points that should be keep into mind while choosing data type to store date and time. DATETIME or TIMESTAMP? Let’s compare.
Methods and tips to prevent SQL Injection attacks
In this article we are presented with few methods and tips to prevent SQL Injection attacks in our web application.
In simple term when an application takes user data as an input, there is an opportunity for a malicious user to enter carefully crafted data that causes the input to be interpreted as part of a SQL query instead of data in our application.
What is SQL Injection
SQL Injection is the hacking technique which attempts to pass SQL commands (statements) through a web application for execution by the backend database. If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection
finding values in comma separated string using mysql
Generally, We give the various options of choices to choose on websites in form of checkbox and stores various values of choices in a column of MySQL database as a comma seperated . For example we store user’s preferred hobby in user table’s hobbies(varchar(250)) field(column). Value stored in this field may be like 1,2,5,6,1 or may be ‘sports’,’gardening’,’cooking’,’reading’.
last day of month in mysql
Sometimes we need to get the last day of the month on specific date in mysql becoz every month has different last day eg. FEB. may have 28 or 29, JAN has 31 and APR has 30.
DAY in MySQL
DAY() in MySQL returns the day of the month for a specified date. The day returned will be within the range of 1 to 31. If the given date is ‘2013-03-13’, the function will return 13.