Karthikeya Boyini has Published 2383 Articles

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

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:26

128 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 ... Read More

How to display grant defined for a MySQL user?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:26

160 Views

Use SHOW GRANTS for this. Following is the syntax −SHOW GRANTS FOR 'yourUserName'@'yourHostName';Let us display the user name and host name from MySQL.user table.mysql> select user, host from MySQL.user;This will produce the following output −+------------------+-----------+ | user | ... Read More

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

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:26

544 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 ... Read More

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

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:26

323 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 ... Read More

Write your own memcpy() in C

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:26

3K+ Views

Here we will see how to implement memcpy() function in C. The memcpy() function is used to copy a block of data from one location to another. The syntax of the memcpy() is like below −void * memcpy(void * dest, const void * srd, size_t num);To make our own memcpy, ... Read More

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

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:26

893 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 -> ... Read More

Best data type for storing large strings in MySQL?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:26

742 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 ... Read More

Average of first n even natural numbers?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:26

605 Views

Average or mean of n even natural number is the sum of numbers divided by the numbers.You can calculate this by two methods &minusFind the sum of n even natural numbers and divide it by number, Using loop.Find the sum of n even natural numbers and divide it by number, ... Read More

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

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:26

97 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       */   ... Read More

Implement MySQL ORDER BY without using ASC or DESC?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:26

96 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 ... Read More

Advertisements