Sharon Christine has Published 413 Articles

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

769 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

666 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

234 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

111 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

95 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

1K+ 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

323 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

MySQL query to search record with apostrophe?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 11:13:57

552 Views

Let us first create a table −mysql> create table DemoTable -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (2.23 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Sam\''s'); ... Read More

Find out the records of students with more than a specific score in MySQL?

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 10:07:06

151 Views

Set it with WHERE and get the records of students more than a specific score. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100),    -> StudentScore int    -> ); Query OK, ... Read More

MySQL query to get the count of distinct records in a column

Sharon Christine

Sharon Christine

Updated on 30-Jun-2020 10:04:28

303 Views

To get the count of distinct records, use DISTINCT along with COUNT(). Following is the syntax −select count(DISTINCT yourColumnName) from yourTableName;Let us first create a table −mysql> create table DemoTable -> ( -> Name varchar(20), -> Score int -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in ... Read More

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