Using GROUP BY on Two Fields and COUNT in MySQL

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

632 Views

To implement GROUP BY on two fields and count, let us create a table. The following is the query to create a table −mysql> create table GroupByTwoFieldsDemo    −> (    −> Id int,    −> Name varchar(200)    −> ); Query OK, 0 rows affected (0.53 sec)Let us insert some records in the table −mysql> insert into GroupByTwoFieldsDemo values(1, 'John'); Query OK, 1 row affected (0.15 sec) mysql> insert into GroupByTwoFieldsDemo values(10, 'Johnson'); Query OK, 1 row affected (0.16 sec) mysql> insert into GroupByTwoFieldsDemo values(9, 'Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More

MySQL Stored Procedure Out Parameter

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

991 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

MySQL Update with REGEXP: Is It Possible?

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

471 Views

You cannot update with regexp i.e. you need to use LIKE operator instead of regexp. MySQL does not provide support for update with regexp. The LIKE operator is as follows:UPDATE yourTableName SET yourColumnName= REPLACE(yourColumnName, yourValue)', '' ) WHERE yourColumnNameLIKE '%yourValueThatWillReplace)%';To understand the above syntax, let us create a table.mysql> create table Replace_Demo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Value varchar(20),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows:mysql> insert into Replace_Demo(Value) values('221)'); Query OK, 1 ... Read More

Display AM/PM Time Marker with SimpleDateFormat in Java

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

933 Views

You can display AM/PM time marker easily in Java using SimpleDateFormat(“a”).Firstly, to work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“a”) to display AM/PM marker −Format f = new SimpleDateFormat(”a”);Now, get the marker in a string −String strMarker = f.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar cal = Calendar.getInstance(); ... Read More

MySQL Query to Return Records Older than 1 Week

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

3K+ Views

To get dates older than 1 week, you can use the following syntax −select *from yourTableName where yourColumnName < now() - interval 1 week;To understand the above concept, let us create a table. The query to create a table is as follows −mysql> create table DatesOfOneWeek −> ( −> ArrivalTime datetime −> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table −mysql> insert into DatesOfOneWeek values(date_add(now(), interval 2 week)); Query OK, 1 row affected (0.11 sec) mysql> insert into DatesOfOneWeek values('2018-11-04'); Query OK, 1 row affected ... Read More

Email and Phone Validation in Swift

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

1K+ Views

To validate email and phone in swift language we can use multiple conditional statements like if conditions, but that’s a long process and may contain 50-100s of if statements to validate email.So instead of conditionals we’ll use Regular expression. Swift provides NSPredicates which we can use to evaluate a regular expression and test them.Let’s see how we can use regular expressions to do the same.We’ll create a function which we can use as extension of String class or UIViewController to use through out the project.Add the following code to any class in your Project, or create a separate swift class ... Read More

FTP SSL Connect Function in PHP

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

344 Views

The ftp_ssl_connect() function opens a secure SSL-FTP connection.Syntaxftp_ssl_connect(host,port,timeout);Parametershost − The FTP server address. Can be a domain address or an IP address.port − The port to connect to. Here the default is 21.timeout − The timeout for network operations.ReturnThe ftp_ssl_connect() function returns a SSL-FTP stream on success or FALSE on error.ExampleThe following is an example −

MySQL Truncate Text with Ellipsis

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

1K+ Views

You can truncate the text with ellipsis using LENGTH() with CASE statement. If your length is greater than 7 then truncate the text and add some number otherwise print the number as it is.To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table TruncateText    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Number longtext,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command. The query is as follows:mysql> insert into TruncateText(Number) values('64575868667687'); ... Read More

Create a Table in MySQL that Matches Another Table

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

226 Views

To create a table in MySQL that matches with another table, use CREATE TABLE command with LIKE operator. The syntax is as follows −create table yourNewTableName like yourOldTableName;The above syntax creates structure of the table.If you want all records then use INSERT INTO…...SELECT *FROM command. The syntax is as follows −insert into yourNewTableName select *from yourOldTableName.I have an old table and some data −mysql> create table WholeWordMatchDemo −> ( −> Words varchar(200) −> ); Query OK, 0 rows affected (0.84 sec)First, we will create a table structure. The query is as ... Read More

Check If MySQL Binary Log is Enabled via SQL Command

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

5K+ Views

to know if MySQL binary log is enabled through SQL command, you can use show variables command.The syntax is as followsshow variables like ‘yourPatternValue’;In place of ‘yourPatternValue’, you can use log_bin to check the binary log is enabled using SQL command show.The query is as followsmysql> show variables like 'log_bin';The following is the output that displays whether it is enabled or not+---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_bin | ON | +---------------+-------+ 1 row in set (0.03 sec)

Advertisements