Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Thursday, December 26, 2013

Use of Select Keyword in Query

1. Finding how many rows in tables.

2. Finding all records from tables; we are using wildcard start * for getting all columns.

3. Selecting few records based on some condition from tables in SQL.

4. Select few columns instead of all columns of a table.

5. Select distinct (unique) records from Columns.

6. Selecting value with condition based on less than, greater than (>, <, >=, <=) etc.

7. Combining condition using logical operator AND & OR.

8. How to find records which is not null using keyword NULL and IS NULL.

9. SELECT Statement using BETWEEN and NOT BETWEEN.

10. Pattern matching in SQL queries using LIKE and NOT LIKE.

11. IN and NOT IN Statement in Query

12. Sorting ResultSet in SQL using ORDER BY, ASC, DESC.

14. Selecting data from multiple tables by using JOIN in SQL.

15. Calling function on SELECT clause e.g. displaying current date.

16. Doing calculation using SELECT CLAUSE.

17. SELECT data from one row till another row like Paging.

18. Selecting data from result of another query by using derived table.

Difference between Candidate Key vs Primary Key in MYSQL

Some Differences are given below.
 1) Both Primary and Candidate keys can uniquely identify records in a table on database.
 2) Both Primary and Candidate keys are has constraints UNIQUE and NOT NULL.
 3) Primary key or Candidate keys can be either single column or combination of multiple columns in a table.


Now from interview point of view here is difference between Candidate key and primary key in SQL table on point format for easy to remember :

1) There can be multiple Candidate keys in a table in relation database e.g. Oracle, MySQL, Sybase or MSSQL but only one primary key is permitted.
2) An example of Primary key and Candidate key can be ID and SSN number in a Employee table, Since both can identify each employee uniquely .They are candidate key and any one can become primary key. Now if you have to choose between them as primary key, I will go ID as primary key because SSN is sensitive information and may not be allow/not safe to use as String in queries as frequently as ID. Second reason of choosing ID over SSN as primary key can be use of ID as primary tracking ID within organization and its frequent use all over the place. Once you choose a primary key,
3) All candidate key  are like unique keys.