Query to obtain rank function in MySQL

There is no rank function in MySQL actually, whenever you need to query rank from table based on some functionality/criteria in MYSQL. But there are simple queries that can be used to perform the same.
Read the article to create query as well as to know about equivalent query for RANK and DENSE_RANK in MySQL.

Read More

Concatenate multiple MySQL rows into one field using GROUP_CONCAT

We can concatenate multiple MySQL rows into one field using GROUP_CONCAT function in mySQL query. There might be situations when you select multiple values from multiple tables and after all the joins you have got a lot of rows than you would like. We can use`GROUP_CONCAT` to obtain the same result with less numbers of rows.

Read More

Get the last inserted ID of a MySQL table in PHP

Get the last inserted ID of a MySQL table is a simple query to obtain the primary key of the record you just inserted to the table. Here I have explained the query using PDO as well as Mysqli.

Also, I have abbreviated few points while using PDO or if you are trying to get the last inserted ID of a MySQL table in PHP using other methods.

Read More

Sum of multiple columns values in a row

With help of the following simple query you can find sum of multiple columns values in a row.

In the `marks` table below we have roll number and marks of each student in physics, chemistry and maths. Now we wish to find sum of marks obtained by each student.

Read More

Retrieving the last record in each group

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.

Read More

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.

Read More

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.

Read More

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

Read More

[ Page 2 of 3 ]