SELECT column_names from table_name [WHERE ...conditions];The conditions part of the statement is optional. Basically, you require to know the column names and the table name from which to extract the data.SELECT f_name, l_name from employee_data;The statement tells MySQL to list all the rows from columns f_name and l_name.The display is in the order in which the data was inserted. Furthermore, the last line indicates the number of rows our table has.
To display the entire table, we can either enter all the column names or use a simpler form of the SELECT statement.
SELECT * from employee_data;Some of you might recognize the * in the above statement as the wildcard. Though we don't use that term for the character here, it serves a very similar function. The * means 'ALL columns'. Thus, the above statement lists all the rows of all columns.ASSIGNMENT 1
- Write the complete SQL statement for creating a new database called addressbook
- Which statement is used to list the information about a table? How do you use this statement?
- How would you list all the databases available on the system?
- Write the statement for inserting the following data in employee_data table
First name: Rudolf
Last name: Reindeer
Title: Business Analyst
Age: 34
Years of service: 2
Salary: 95000
Perks: 17000
email: rudolf@bugnet.com - Give two forms of the SELECT statement that will list all the data in employee_data table.
- What will select f_name, email from employee_data; display?
- Write the statement for listing data from salary, perks and yos columns of employee_data table.
- How can you find the number of rows in a table using the SELECT statement?
- What will select salary, l_name from employee_data; display?
selecting data using conditions
We will learn how to use the select statement using the WHERE clause.SELECT column_names from table_name [WHERE ...conditions];Now, we know that the conditions are optional Comparision Operators of SQL
1)SELECT f_name, l_name from employee_data where f_name =’john';This query displays the first and last names of all employees whose first names are John.
2) SELECT f_name,l_name from employee_data where title="Programmer";
3) SELECT f_name, l_name from employee_data where age = 32;
1) SELECT f_name, l_name from employee_data where age > 32;
2) SELECT f_name, l_name from employee_data where salary > 120000;
3) SELECT f_name, l_name from employee_data where yos < 3;
1) select f_name, l_name, age, salary
from employee_data where age >= 33;This query display the names, ages and salaries of employees who are more than or equal to 33 years of age.2) select f_name, l_name from employee_data where yos <= 2;This query displays employee names who have less than or equal to 2 years of service in the company.ASSIGNMENT 2
- Write the SELECT statement to extract the ids of employees who are more than 30 years of age.
- Write the SELECT statement to extract the first and last names of all web designers.
- What will the following SELECT statement display:
4. SELECT * from employee_data where salary <=100000;
- How will you display the salaries and perks for employees who have more than $16000 as perks?
- List all employee names (last name followed by first name) who hold the title of Marketing Executive.
No comments:
Post a Comment