Sharon Christine has Published 436 Articles

How to place number 0 from a column at the end maintaining the ascending search order in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 12:13:44

59 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Number int    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(9); Query OK, 1 row affected (0.13 sec) mysql> insert ... Read More

Fix Error with TYPE=HEAP for temporary tables in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 12:11:41

163 Views

The TYPE=HEAP deprecated in newer MySQL versions. You can use ENGINE=HEAP instead of TYPE. Following is the syntax −ENGINE=HEAP;Let us first create a table. Here, we have set Engine=HEAP −mysql> create TEMPORARY table DemoTable    -> (    -> StudentId int,    -> StudentName varchar(30)    -> )Engine = HEAP; ... Read More

MySQL query to order by two fields and NULL values in chronological order?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 11:51:42

186 Views

Let us first create a table −mysql> create table DemoTable -> ( -> FirstName varchar(100), -> LastName varchar(100) -> ); Query OK, 0 rows affected (1.39 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Sam', 'Brown'); Query OK, 1 row affected (0.25 sec) mysql> ... Read More

MySQL DATE_ADD() to increment a date based on the value in another column?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 11:47:25

562 Views

Let us first create a table with one of the columns as DueDate and another one “RepeatTime, which displays how many times, let’s say a user was reminded to submit the payment −mysql> create table DemoTable    -> (    -> DueDate date,    -> RepeatTime int    -> ); ... Read More

Change a MySQL column to have NOT NULL constraint

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 11:45:00

521 Views

To update the constraint, use the MODIFY command. Following is the syntax −alter table yourTableName modify yourExistingColumnName yourExistingDataType NOT NULL;  Let us first create a table −mysql> create table DemoTable    -> (    -> UserId int NOT NULL AUTO_INCREMENT,    -> UserFirstName varchar(100),    -> UserLastName varchar(100),    -> ... Read More

Is there a default ORDER BY value in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 11:35:40

165 Views

There is no default ORDER BY value in MySQL. You need to specify ORDER BY clause explicitly. Following is the syntax −ORDER BY ASC; OR ORDER BY DESC;Let us first create a table −mysql> create table DemoTable    -> (    -> StudentName varchar(100)    -> ); Query OK, 0 ... Read More

Fetch a single ordered date from a column with MySQL LIMIT

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 11:24:45

69 Views

To fetch a single date from a column, use “LIMIT 1. To order it, use ORDER BY clause. Let us first create a table −mysql> create table DemoTable -> ( -> DueDate varchar(100) -> ); Query OK, 0 rows affected (1.16 sec)Insert some records in the table using insert command ... Read More

Pad the displayed value of the field with zeros up to the display width specified in the column definition in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 11:23:59

50 Views

Use zerofill for this in MySQL. Zerofill pads the displayed value of the field with zeros up to the display width specified in the column definition. For example, if column is set int(8), therefore the width is 8. If the number is let’s say 29654, then zero will be padded ... Read More

How to update only day portion of MySQL Date?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 11:21:41

911 Views

Let us first create a table −mysql> create table DemoTable -> ( -> AdmissionDate date -> ); Query OK, 0 rows affected (1.38 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-05-12'); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable values('2019-05-18'); ... Read More

Update column data without using temporary tables in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 11:20:32

215 Views

For this, use CASE statement. This will work even without using temporary tables. Let us first create a table −mysql> create table DemoTable    -> (    -> UserName varchar(100),    -> UserStatus varchar(100)    -> ); Query OK, 0 rows affected (0.74 sec)Insert some records in the table using ... Read More

Previous 1 ... 7 8 9 10 11 ... 44 Next
Advertisements