Back to Top
Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Sunday, 17 March 2013

SQL: OR Command

In SQL, we have seen the use of AND command, to set multiple condition when performing a database transaction. But when we use AND, that means it's a mandatory condition. The transaction will provide output, only when all the conditions will be satisfied. But, what about an optional condition? Do SQL have any provision for that? The Answer is yes. SQL Do have command named OR to set optional condition.

Syntax: SELECT [column_name] FROM [table_name] WHERE [condition_1] OR [condition_2];

Here, output will come if [condition_1] OR [condition_2] OR both satisfied. That means, it is SELECT [column_name] FROM [table_name] WHERE [condition_1] OR [condition_2] OR both applied.


Example:

Again, we will use the same table, to see the usage of  OR command.
Table Name:

Employee Details ( employee_details)
Column Names:
Employee ID ( emp_id), 

Employee Name (emp_name), 
Employee Address (emp_address) and
Employee Role: (emp_role).

Table:  employee_details 


Now, using OR command, we will SELECT those tuple, WHERE emp_role is 'Developer' or 'Business Analyst'.
So, the query will be :

SELECT * FROM employee_details WHERE emp_role = 'Developer' OR emp_role = 'Business Analyst';

Result:











Sunday, 17 March 2013 by Anijit Sarkar · 0 Read more »

Friday, 1 March 2013

SQL: AND Command

In SQL, we have, seen that, we can add conditions by using WHERE command, during any SELECT, UPDATE or DELETE operation. Now, what about multiple conditions? For that, SQL provides to add multiple condition by using AND command. it can be used as many times as you want.

Syntax: SELECT [column_name] FROM [table_name] WHERE [condition_1] AND [condition_2];

[Note: AND means mandatory condition, that means, the operation has to always fulfill the criteria provied under AND block. ]

Example:

Again, use the same table, we will see the usage of  AND command.
Employee Details ( employee_details), which contains 
Employee ID ( emp_id), 

Employee Name (emp_name), 
Employee Address (emp_address) and
Employee Role: (emp_role).

Table:  employee_details 







Now, using AND command, we will SELECT those tuple, WHERE emp_role is 'Developer' and emp_address is 'Park Street, Kolkata'.
So, the query will be :

SELECT * FROM employee_details WHERE emp_role = 'Developer' AND emp_address = 'Park Street, Kolkata';

Result:




In this way, we can use multiple conditions on an RDBMS operation.

Friday, 1 March 2013 by Anijit Sarkar · 0 Read more »

Saturday, 23 February 2013

SQL: WHERE Command

In SQL,when ever you want to SELECT some data, or UPDATE or DELETE some information from a Table, you needs to provide some condition, on basis of which operation will be performed. It's not necessary to SELECT, UPDATE or DELETE all data from a table or view. So, condition is necessary to filter the data when performing an operation on database. The basic structure of of WHERE conditions is :

  Syntax: SELECT [column_name] FROM [table_name] WHERE [condition]

Example:

Again, we will see the same table
Employee Details ( employee_details), which contains 
Employee ID ( emp_id), 

Employee Name (emp_name), 
Employee Address (emp_address) and
Employee Role: (emp_role).

Table:  employee_details 






Now, from this table, if a situation ariser, where we have to just select the information of the developers, the we have to set some condition on our SELECT query, so that we can get the details of the employees with 'emp_role' 'Developer' . Then the Query will be

SELECT * FROM employee_details WHERE emp_role = 'Developer';

Result:





In this way we can filter our data output.

Saturday, 23 February 2013 by Anijit Sarkar · 1 Read more »

Sunday, 17 February 2013

SQL: SELECT Command

SELECT command is use in SQL to "SELECT [some info] FROM [a location]".  Now, this is the basic structure of the SELECT query, where SELECT and FROM are 2 commands of SQL. Here, [some info] part will be the column names separated by comma (,) sign and [a location] part will be the name of the Table or View. So, the syntax will be :

For Single Column :
Syntax : SELECT [Column_name] FROM [Table_Name];

For Multiple Columns :
Syntax : SELECT [Column1_name, Column2_name, Column3_name] FROM [Table_Name];


Now, what if you want to select all the columns of a table or a view. Do you have to write all the column name for that. No necessarily, you can user the star (*) sign in [Column_name] area. Then the syntax will be:

For All Columns :
Syntax : SELECT * FROM [Table_Name];

Example:
Suppose there is a table to keep
Employee Details (Table Name: employee_details), which contains
Employee ID(Column Name: emp_id), 

Employee Name(Column Name: emp_name), 
Employee Address:(Column Name: emp_address) and
Employee Role: (Column Name: emp_role).

Table:  employee_details 





 Now, to select emp_id and emp_name from the table, the query will be,

SELECT emp_id, emp_name FROM employee_details;

Result:


 Again, if you wants to select all the colunms' record, then the query will be,

 SELECT * FROM employee_details;

Result:

 

Sunday, 17 February 2013 by Anijit Sarkar · 1 Read more »

Thursday, 14 February 2013

SQL: What is SQL

  SQL (Structured Query Language) is a type of programming language, which uses to communicate with database. It’s also known as “sequel”. It provides some syntax which helps you to interact with a database. These syntax are very similar to normal English language, so it’s easy to remember and use. Now a day, all major RDBMS (Relational Database Management System)  like MySQL, Oracle, postgres, MS Access and SQL Server uses SQL to maintain data.

  SQL helps to store, manipulate, read and delete data from data base. It helps to performs the CRUD(Create, Read, Update & Delete) operations in RDBMS.

Create: It helps to create database, schema, table  and view, along with there properties.

Read: It helps to select all information from single or multiple records from one or many table or view.

Update: It also helps us to manipulates existing data in a database.

Delete: It can also delete information or structure of database or table.

Thursday, 14 February 2013 by Anijit Sarkar · 4 Read more »

Popular Posts

All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar