Tutorialspoint

Sort by character length in MySQL

George John
Answered on 17th Apr, 2019

To sort by character length in MySQL use the ORDER BY LENGTH(). Let us first create a table:mysql> create table orderingAADemo    -> (    -> Value varchar(100)    -> ); Query OK, 0 rows affected (1.30 sec)Following is the query to insert some records in the table using insert ... Read More

How to suppress MySQL stored procedure output?

George John
Answered on 17th Apr, 2019

To suppress MySQL stored procedure output, you can use variable. Let us first create a table.mysql> create table person_information    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.50 sec)Following is the query to insert some records in the table ... Read More

How to add column using alter in MySQL?

George John
Answered on 17th Apr, 2019

Following is the syntax to add column using alter in MySQL:alter table yourTableName add column yourColumnName yourDataType default yourValue;Let us first create a table:mysql> create table alterTableDemo    -> (    -> Id int,    -> Name varchar(10)    -> ); Query OK, 0 rows affected (0.69 sec)Let us check ... Read More

Can we order a MySQL result with mathematical operations?

George John
Answered on 17th Apr, 2019

Yes, we can order with mathematical operations using ORDER BY clause. Let us first create a table:mysql> create table orderByMathCalculation    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Quantity int,    -> Price int    -> ); Query OK, 0 rows affected (0.57 sec)Following ... Read More

Resolve Unknown database in JDBC error with Java-MySQL?

George John
Answered on 17th Apr, 2019

This type of error occurs if you select any database that does not exist in MySQL. Let us first display the error of unknown database in JDBC.The Java code is as follows. Here, we have set the database as ‘onlinebookstore’, which does not exist:import java.sql.Connection; import java.sql.DriverManager; public class UnknownDatabaseDemo ... Read More

How do I INSERT INTO from one MySQL table into another table and set the value of one column?

Nishtha Thakur
Answered on 16th Apr, 2019

Let us first create a table. Following is the query −mysql> create table insertOneToAnotherTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.60 sec)Following is the query to insert some records in the table using insert command −mysql> insert into insertOneToAnotherTable values(100); Query ... Read More

Select results from the middle of a sorted list in MySQL?

Smita Kapse
Answered on 16th Apr, 2019

To select results from the middle of a sorted list, use ORDER BY clause along with LIMIT.Let us first create a table. Following is the query −mysql> create table sortedListDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100)    -> ); Query ... Read More

Reorder integer except for value 0 with MySQL?

Anvi Jain
Answered on 16th Apr, 2019

To reorder integer except for value 0, use the below syntax −select *from yourTableName order by yourColumnName=0 ,yourColumnName;Let us first create a table −mysql> create table reorderIntegerExcept0    -> (    -> value int    -> ); Query OK, 0 rows affected (0.70 sec)Following is the query to insert records ... Read More

How to check privileges in MySQL?

Nishtha Thakur
Answered on 16th Apr, 2019

To check privileges, use SHOW command with GRANTS. Following is the syntax −SHOW GRANTS;The above syntax will show privileges for root. If you want to check privileges for a specific user, then use the below syntax −SHOW GRANTS FOR 'yourUserName'@'yourHostName';The above syntax will check privileges for a specific user.Let us ... Read More

Insert current date to the database in MySQL?

Smita Kapse
Answered on 16th Apr, 2019

To insert current date to the database, you can use NOW(). Following is the syntax −INSERT INTO yourTableName(yourDateColumnName) VALUES(NOW());If your column has datatype date then NOW() function inserts only current date, not time and MySQL will give a warning. To remove the warning, you can use CURDATE().Let us first create ... Read More

MySQL format time with lowercase am/pm?

Anvi Jain
Answered on 16th Apr, 2019

To format MySQL time with lowercase am/pm, use the LOWER() as well as DATE_FORMAT().Let us first create a table −mysql> create table formatTime    -> (    -> LoginTime time    -> ); Query OK, 0 rows affected (0.56 sec)Following is the query to insert records in the table using ... Read More

Can we GROUP BY one column and select all data in MySQL?

Smita Kapse
Answered on 16th Apr, 2019

Yes, you can use group_concat() for this. Let us first create a table −mysql> create table groupByOneSelectAll    -> (    -> StudentDetails varchar(100),    -> StudentName varchar(100)    -> ); Query OK, 0 rows affected (0.91 sec)Following is the query to insert some records in the table using insert ... Read More

Add10 minutes to MySQL datetime format?

Nishtha Thakur
Answered on 16th Apr, 2019

Use DATE_ADD() to add 10 minutes to datetime format. Following is the syntax −select date_add(yourColumnName ,interval 10 minute) from yourTableName;Let us first create a table −mysql> create table add10MinuteDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> DelayDatetime datetime    -> ); Query OK, ... Read More

How to use the CAST function in a MySQL SELECT statement?

Anvi Jain
Answered on 16th Apr, 2019

The CAST() function in MySQL converts a value of any type into a value that has a specified type. Let us first create a table −mysql> create table castFunctionDemo    -> (    -> ShippingDate date    -> ); Query OK, 0 rows affected (0.74 sec)Following is the query to ... Read More

How to compare timestamps in MySQL?

Nishtha Thakur
Answered on 16th Apr, 2019

To compare timestamps in MySQL, you can use DATE(). Let us first create a table−mysql> create table comparingTimestampDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> AdmissionDate timestamp    -> ); Query OK, 0 rows affected (0.54 sec)Following is the query to insert records ... Read More

Previous 1 ... 3 4 5 6 7 8 9 ... 1284 Next
Advertisements
Loading...
Unanswered Questions View All

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.