Possible MySQL interview questions

1. If we login more than one browser window at the same time with same user and after that we close one window then is the session is exist to other window or not.And if yes then why? or if no then why?
session depends on browser. if browser is closed then session is lost. the session data will be deleted after session time out. if connection is lost and u recreate connection, then also sesssion will continue in the browser.
2. How can we find the number of rows in a table using MySQL?
Use this for mysql
>SELECT COUNT(*) FROM table_name;
but if You Are particular about no of rows with some special result. do this:
>SELECT [colms],COUNT(*) FROM table_name [where u put conditions];
3. How many ways we can we find the current date using MySQL?
SELECT CURDATE();
CURRENT_DATE() = CURDATE()
for time use
SELECT CURTIME();
CURRENT_TIME() = CURTIME()
4. What is the difference between GROUP BY and ORDER BY in Sql?
ORDER BY [col1],[col2],…,[coln]; Tels DBMS according to what columns it should sort the result. If two rows will hawe the same value in col1 it will try to sort them according to col2 and so on.
GROUP BY [col1],[col2],…,[coln]; Tels DBMS to group results with same value of column col1. You can use COUNT(col1), SUM(col1), AVG(col1) with it, if you want to count all items in group, sum all values or view average
5. What is the difference between char and varchar data types?
Set char to occupy n bytes and it will take n bytes even if u r storing avalue of n-m butes
Set varchar to occupy n bytes and it will take only the required space and will not use the n bytes
eg. name char(10) will waste 5 bytes if we store ‘kumar’, if each char takes a byte
eg. name varchar(10) will just use 5 bytes if we store ‘kumar’, if each char takes a byte. rest 5 bytes will be free.
6. How can I load data from a text file into a table?
The mysql provides a LOAD DATA INFILE syntax. U can load data from a file. Gr8 tool but u need to make sure that
a) data is delimited
b) u match the colms and data correctly
dont use w/out first learning the syntax
eg.:- $sql = 'LOAD DATA LOCAL INFILE ''I:/wamp_install/tmp\\\\php19.tmp'' INTO TABLE `webprogrammer` FIELDS TERMINATED BY '';'' ENCLOSED BY ''"'' ESCAPED BY ''\\\\'' LINES TERMINATED BY ''\\r\\n''';
7. How can we know the number of days between two given dates using MySQL?
Use DATEDIFF()
>SELECT DATEDIFF(NOW(),’1947-08-15′);
will give u the exact no of days India got independence from British.
8. What is MySQL?
MySql is a Relational database management system, provided from open source community. Currently fast growing and hight used RDBMS. MySql Developed by MySql AB.

9. difference between mysql_num_rows() and mysql_num_fields()?
mysql_num_rows():- returns the number of rows in the result set.
mysql_num_fields():- returns the number of fields in the result set

10. Explain SQL HAVING:
The sQL HAVING clause is used to do exactly this, to specify a condition for an aggregate function.
or

SQL GROUP BY:
The sQL GROUP BY statement is used along with the SQL aggregate functions like SUM to provide means of grouping the result dataset by certain database table column(s).
or

SQL ORDER BY:
The sQL ORDER BY clause comes in handy when you want to sort your SQL result sets by some column(s).
or
The order by statement allows for table column assortment. It allows for ascending or descending lists of your table column values permitting SQL to reorder your table rows for the purpose of viewing.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...