Chandu yadav has Published 1090 Articles

Select last 20 records ordered in ascending order in MySQL?

Chandu yadav

Chandu yadav

Updated on 30-Jul-2019 22:30:24

659 Views

To select last 20 records in ascending order, you can use subquery LIMIT clause. The syntax is as followsSELECT *FROM (    SELECT *FROM yourTableName ORDER BY yourColumnName desc limit 20 ) anyVariableName order by anyVariableName.yourColumnName;To understand the above syntax, let us create a table. The query to create a ... Read More

Difference between two selects in MySQL?

Chandu yadav

Chandu yadav

Updated on 30-Jul-2019 22:30:24

2K+ Views

You can use subqueries for difference between two selects in MySQL. The syntax is as follows:SELECT *FROM yourTableName where yourColumnName NOT IN(SELECT yourColumnName FROM youTableName WHERE yourCondition;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table DifferenceSelectDemo    -> ... Read More

Create a procedure in MySQL with parameters?

Chandu yadav

Chandu yadav

Updated on 30-Jul-2019 22:30:24

4K+ Views

You can create a parameter using IN and OUT. IN is used to take input parameter and OUT can be used for output.The syntax is as followsDELIMITER // CREATE PROCEDURE yourProcedureName(IN yourParameterName dataType, OUT yourParameterName dataType ) BEGIN yourStatement1; yourStatement2; . . N END; // DELIMITER ;First, ... Read More

How to find nth highest value of a MySQL column?

Chandu yadav

Chandu yadav

Updated on 30-Jul-2019 22:30:24

661 Views

To find the nth highest value of a column, you need to use ORDER BY DESC with LIMIT clause. If you want the second highest value of a column, use the below syntax:SELECT *FROM yourTableName ORDER BY DESC yourColumnName LIMIT 1, 1;If you want the fourth highest value of a ... Read More

Check if a string contains numbers in MySQL?

Chandu yadav

Chandu yadav

Updated on 30-Jul-2019 22:30:24

3K+ Views

To check a string contains numbers, you can use regexp i.e. Regular Expressions. The syntax is as follows −SELECT *FROM yourTableName where yourColumnName REGEXP ‘[0-9]’;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table StringContainsNumber    -> ( ... Read More

How do you OR two MySQL LIKE statements?

Chandu yadav

Chandu yadav

Updated on 30-Jul-2019 22:30:24

164 Views

You can OR two like statements using the following syntax −SELECT *FROM yourTableName WHERE (yourColumnName like '%yourValue1%' OR yourColumnNamelike '%yourValue2%') AND yourColumnName = yourValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ORLikeDemo    -> (   ... Read More

SHOW TABLE statement with multiple LIKE values in MySQL?

Chandu yadav

Chandu yadav

Updated on 30-Jul-2019 22:30:24

510 Views

You can use WHERE clause and OR operator to show table with multiple LIKE. The syntax is as follows:show table from yourDatabaseName where tables_in_yourDatabaseName Like ‘%anyTableName%’ or tables_in_yourDatabaseName Like ‘%anyTableName2%’ or tables_in_yourDatabaseName Like ‘%anyTableName3%’ . . . . or tables_in_yourDatabaseName Like ‘%anyTableNameN%’In the above syntax, only the table name in ... Read More

Low-level networking interface in Python (socket)

Chandu yadav

Chandu yadav

Updated on 30-Jul-2019 22:30:24

1K+ Views

The 'socket' module in Python's standard library defines how server and client machines can communicate using socket endpoints on top of the operating system. The 'socket' API contains functions for both connection-oriented and connectionless network protocols.Socket is an end-point of a two-way communication link. It is characterized by IP address ... Read More

How can I merge two MySQL tables?

Chandu yadav

Chandu yadav

Updated on 30-Jul-2019 22:30:24

4K+ Views

To merge two MySQL tables, use the following syntax −INSERT IGNORE INTO yourTableName1 select *from yourTableName2;We will create two tables with some records. After that the merge process will begin using the above syntax.Creating first table −mysql> create table MergeDemo1 -> ( -> id ... Read More

Grant a user permission to only view a MySQL view?

Chandu yadav

Chandu yadav

Updated on 30-Jul-2019 22:30:24

1K+ Views

To grant a user permission to only view a MySQL view, use the below syntaxGRANT SELECT ON yourDatabaseName.yourViewName TO ' yourUserName@'yourLocalHost';First you need to display all the view names from a table. The syntax is as follows −SHOW FULL TABLES IN yourDatabaseName WHERE TABLE_TYPE LIKE 'VIEW';Now implement the above syntax ... Read More

Advertisements