Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2015 October MySQL: Query Interview Questions and Answers

MySQL: Query Interview Questions and Answers

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

I require selecting 10 records at a time and at the same time I also require to know the total count of records.
How would you do this?

You can use SQL_CALC_FOUND_ROWS in SELECT statement and execute FOUND_ROWS().
Sample query:

1
2
SELECT SQL_CALC_FOUND_ROWS * FROM Test LIMIT 10;
SELECT FOUND_ROWS();

The First statement will return your 10 records and second statement will return total count of records.
The FOUND_ROWS() function will not internally use COUNT so it performs better.

Find all database starting with ‘db’.

1
SHOW DATABASES LIKE 'db%';

How to concatenate this two string?

String 1: ‘My name is Anvesh.’

String 2: ‘I am Database Administrator.’

1
SELECT CONCAT('My name is Anvesh.',' I am Database Administrator.');

How to get a portion of a string by specifying position?

1
SELECT SUBSTR('I am Anvesh Patel',6,6);

How to select month from given date?

1
2
SELECT MONTH(NOW());
SELECT MONTHNAME(NOW());

How to format date in MM-DD-YY format?

1
SELECT DATE_FORMAT(NOW(),'%m-%d-%y');

How to format date in week – day – month – year format?

1
SELECT DATE_FORMAT(NOW(),'%W %D %M %Y');

How to copy the only table structure and create a new table?

1
CREATE TABLE Test2 AS SELECT *FROM Test WHERE 1=2;

How to make copies of the table with data and structure?

1
CREATE TABLE Test2 AS SELECT *FROM Test;

What are the result of below queries?

1
SELECT NULL + 8 FROM DUAL;

Result : NULL

1
SELECT NULL OR TRUE FROM DUAL;

Result : 1

1
SELECT NULL AND TRUE FROM DUAL;

Result : NULL

How to convert numeric values to strings?

1
SELECT CAST(88.808 AS CHAR) FROM DUAL;

How to convert string values to Date format?

1
SELECT STR_TO_DATE('08-Aug-2015 8:08:08', '%d-%b-%Y') FROM DUAL;

How to add new column to an existing table?

1
ALTER TABLE test ADD COLUMN RecordDateTime DATETIME;

How to drop column from an existing table?

1
ALTER TABLE test DROP COLUMN RecordDateTime;

How to rename a column in an existing table?

1
ALTER TABLE Test CHANGE COLUMN OldColumnName NewColumnName INTEGER;

How to rename existing Table?

1
ALTER TABLE Test rename to Test2;

How to drop index of a table?

1
DROP INDEX idx_tbl_test_rno ON test;

Check running all MySQL Server Processes.

1
mysqladmin -u root -p processlist

Command to shutdown MySQL.

1
mysqladmin -u root -p shutdown

Check MySQL current version.

1
mysqladmin -u root -p version

Check MySQL is running or not.

1
mysqladmin -u root -p ping

How to list all databases from the MySQL Server?

1
Show databases;

How to switch or use to a database?

1
Use MyDatabase;

How to list all tables from the MySQL Server?

1
Show tables;

How to see a description or definition of the Table?

1
describe tablename;

How to find top N records for each group?
Please visit this post:

How to arrange rows to columns Pivot table in MySQL?
Please visit this post:

How to calculate Rank in MySQL Query?
Please visit this post:

How to write Insert-Update, merge statement in MySQL?
Please visit this post:

How to insert a record if not exists in MySQL?
Please visit this post:

Oct 9, 2015Anvesh Patel
PostgreSQL: Fast way to find the row count of a TablePostgreSQL: Insert - Update or Upsert - Merge using writable CTE
Anvesh Patel
Anvesh Patel

Database Engineer

October 9, 2015 MySQL, MySQL InterviewAnvesh Patel, database, database research and development, dbrnd, interview, MySQL, MySQL Command, MySQL Database Administrator, MySQL Database Designing, MySQL Database Programming, MySQL Error, MySQL Performance Tunning, MySQL Query, MySQL Tips and Tricks, practical, query
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....