Found 4378 Articles for MySQL

MySQL stored-procedure: out parameter?

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

753 Views

Here is a stored procedure that takes one parameter for input (IN) and second parameter for output (OUT)mysql> delimiter // mysql> create procedure Sp_SQRT(IN Number1 INT, OUT Number2 FLOAT) -> Begin -> set Number2=sqrt(Number1); -> end; -> // Query OK, 0 rows affected (0.24 sec) mysql> delimiter ;Call the stored procedure and send the value to the user variable. The syntax is as followsCALL yourStoredProcedureName(anyIntegerValue, @anyVariableName);Check what value is stored in the variable @anyVariableName. The syntax is as followsSELECT @anyVariableName;Created the stored procedure with the name ‘Sp_SQRT’. The ... Read More

What is the difference between int and integer in MySQL?

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

2K+ Views

The int is the synonym of integer in MySQL 5.0. Here is the demo display both int and integer internally represents int(11).Creating a table with int datatypemysql> create table IntDemo    -> (    -> Id int    -> ); Query OK, 0 rows affected (1.04 sec)Here is description of the table. The query is as followsmysql> desc IntDemo;The following is the output+-------+---------+------+-----+---------+-------+ | Field | Type    | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | Id    | int(11) | YES  |     | NULL    |       | +-------+---------+------+-----+---------+-------+ 1 row in ... Read More

Split the left part of a string by a separator string in MySQL?

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

404 Views

You can use substring_index() function from MySQL to split the left part of a string. The syntax is as follows −SELECT yourColumnName1, .....N, SUBSTRING_INDEX(yourColumnName, ’yourSeperatorSymbol’, 1) as anyVariableName from yourTableName;The value 1 indicates that you can get left part of string. To check the above syntax, let us create a table. The query to create a table is as follows −mysql> create table LeftStringDemo -> ( -> Id int, -> Words varchar(100) -> ); Query OK, 0 rows affected (0.92 sec)Insert some records in the table using insert ... Read More

How to order DESC by a field, but list the NULL values first?

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

61 Views

To order by a field and list the NULL values first, you need to use the following syntax. This will order in descending order −select yourColumnName from yourTableName group by yourColumnName is null desc, yourColumnName desc;To understand the above syntax, let us first create a table −mysql> create table OrderByNullFirstDemo    −> (    −> StudentId int    −> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table with the help of insert command. The query is as follows −mysql> insert into OrderByNullFirstDemo values(100); Query OK, 1 row affected (0.13 sec) mysql> insert into OrderByNullFirstDemo ... Read More

Get timestamp date range with MySQL Select?

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

933 Views

To select timestamp data range, use the below syntax −SELECT *FROM yourTableName where yourDataTimeField >= anyDateRange and yourDataTimeField < anyDateRangeTo understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DateRange −> ( −> DueTime timestamp −> ); Query OK, 0 rows affected (1.34 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into DateRange values('2016-11-13'); Query OK, 1 row affected (0.51 sec) mysql> insert into DateRange values('2016-10-14'); Query OK, 1 row ... Read More

How do I begin auto increment from a specific point in MySQL?

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

278 Views

To begin auto increment from a specific point, use ALTER command. The syntax is as follows −ALTER TABLE yourTableName auto_increment = anySpecificPoint;To understand the above concept, let us create a table. The query to create a table is as follows −mysql> create table AutoIncrementSpecificPoint −> ( −> BookId int auto_increment not null, −> Primary key(BookId) −> ); Query OK, 0 rows affected (0.56 sec)Now you can insert records using insert command.The query is as follows −mysql> insert into AutoIncrementSpecificPoint values(); Query OK, 1 row affected (0.17 sec) ... Read More

How to implement a Keyword Search in MySQL?

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

1K+ Views

To implement a keyword search in MySQL, you can use LIKE operator. The syntax is as follows −SELECT *FROM yourTableName where yourColumnName Like ‘%anyKeywordName%’ or yourColumnName Like ‘%anyKeywordName%’;To understand it further, let us first create a table. The following is the query to create a table −mysql> create table KeywordSearchDemo    −> (    −> StudentId int    −> ,    −> StudentName varchar(100)    −> ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using INSERT command. The query to insert record is as follows −mysql> insert into KeywordSearchDemo values(100, 'Adam John'); Query OK, 1 ... Read More

Equaivalent of Oracle concatenation operator in MySQL?

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

87 Views

The concat operator can be used in ORACLE. MySQL use concat() function to perform concatenation.To understand the concat() function, let us create a table. The query to create a table is as follows −mysql> create table ConcatenationDemo −> ( −> Id int, −> Name varchar(100) −> ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ConcatenationDemo values(100, 'John'); Query OK, 1 row affected (0.19 sec) mysql> insert into ConcatenationDemo values(101, 'Sam'); Query ... Read More

Insert the results of a MySQL select? Is it possible?

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

94 Views

You do not need to use values whenever you insert the results of a select. To insert the results of select, let us first create two tables.The first table query is as follows −< FirstTableDemo> mysql> create table FirstTableDemo    −> (    −> StudentId int,    −> StudentName varchar(100)    −> ); Query OK, 0 rows affected (0.41 sec)Now create second table and after that insert the second table records in the first table using INSERT SELECT command.The query to create the second table − mysql> create table SecondTableDemo    −> (    −> Id int,    −> ... Read More

Is MySQL LIMIT applied before or after ORDER BY?

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

93 Views

The MySQL LIMIT is applied after ORDER BY. Let us check the limit condition. Firstly, we will create a table −mysql> create table LimitAfterOrderBy    −> (    −> Id int,    −> Name varchar(100)    −> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into LimitAfterOrderBy values(101, 'John'); Query OK, 1 row affected (0.18 sec) mysql> insert into LimitAfterOrderBy values(102, 'Carol'); Query OK, 1 row affected (0.15 sec) mysql> insert into LimitAfterOrderBy values(103, 'Bob'); Query OK, 1 row affected (0.21 sec) ... Read More

Advertisements