karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 116 of 143

How to correctly use INSERT INTO … SELECT in MySQL to avoid Error 1064?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 719 Views

Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(100)    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(FirstName) values('John'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1(FirstName) values('Chris'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+----+-----------+ | Id | FirstName | +----+-----------+ | 1 | John ...

Read More

How can we grant a user to access all stored procedures in MySQL?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 1K+ Views

Let us first display all users and host from the table MySQL.user −mysql> select user, host from Mysql.user;This will produce the following output −+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | %         | | Charlie          | %         | | Robert           | %         | | User2 | % ...

Read More

Print a long int in C using putchar() only

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 2K+ Views

Here we will see how to print long int value using the putchar() function in C. We can easily print the value of some variables using printf() in C, but here the restriction is, we cannot use any other function except putchar().As we know that the putchar() is used to print only characters. We can use this function to print each digit of the number. When one numeric value is passed, we have to add character ‘0’ with it to get the ASCII form. Let us see the code to get the better idea.Example#include void print_long(long value) {   ...

Read More

Can we return query results in same order as the values in MySQL `IN(…)` statement?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 273 Views

Yes, you can achieve this with ORDER BY FIELD() from MySQL. Let us first create a table −mysql> create table DemoTable -> ( -> Number int -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(19); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(34); Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values(28); Query OK, 1 row ...

Read More

Split a column after hyphen in MySQL and display the remaining value?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 759 Views

To split a column after hyphen, use the SUBSTRING_INDEX() method −select substring_index(yourColumnName, '-', -1) AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable -> ( -> StreetName text -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Paris Hill St.-CA-83745646') ; Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values('502 South Armstrong Street-9948443'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from ...

Read More

How to cut part of a string with a MySQL query?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 421 Views

For this, use substring_index() function from MySQL. Let us first create a table −mysql> create table DemoTable -> ( -> StudentId varchar(100) -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('STU-1011'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('STU-95968686'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------------+ | StudentId | +--------------+ | STU-1011 ...

Read More

How to extract the area codes from a phone number with MySQL?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 1K+ Views

Let’s say we have a list of phone numbers and from that we want to get the area codes. These area codes are for example, the first 3 digits of the phone number. Use LEFT() function from MySQL for this.Let us first create a table −mysql> create table DemoTable -> ( -> AreaCodes varchar(100) -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. Here, let’s say we have included the phone numbers −mysql> insert into DemoTable values('90387568976') ; Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('90389097878' ; ...

Read More

Best data type for storing large strings in MySQL?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 957 Views

You can use text data type to store large strings. Following is the syntax −CREATE TABLE yourTableName (    yourColumnName text,    .    .    N );Let us first create a table −mysql> create table DemoTable -> ( -> MyStringValue text -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('This is a text data type to store large string'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from ...

Read More

C++ Program to Find Second Smallest of n Elements with Given Complexity Constraint

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 182 Views

This is a C++ program to find Second Smallest of n elements with given complexity constraint.AlgorithmBegin    function SecondSmallest() :       /* Arguments to this function are:          A pointer array a.          Number of elements n       */    // Body of the function:       A variable s1 is declared as to keep track of smallest number.       A variable s2 is declared as to keep track of second smallest number.       Initialize both s1 and s2 with INT_MAX.       Traverse ...

Read More

Implement MySQL ORDER BY without using ASC or DESC?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 195 Views

For this, you can use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable -> ( -> Number int -> ); Query OK, 0 rows affected (2.25 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.91 sec) mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.69 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.72 sec) mysql> insert into DemoTable values(800); Query OK, 1 row affected (0.75 sec)Display all records ...

Read More
Showing 1151–1160 of 1,421 articles
« Prev 1 114 115 116 117 118 143 Next »
Advertisements