SQL Flashcards
How to select salary and add 300?
select salary, firstname, salary+300 from employees;
Use aliases for select firstname and say name
select first_name as FirstName from Employees;
Use aliases for select firstname and say name
select first_name as FirstName from Employees;
Concatenate firstname and lastname and alias as full name
select firstname||lastname as fullname from employees;
Get this output for me: "Nilima is a programmer" and nilima = firstname job = programmer with alias
select firstname ||’is a ‘|| job as employee_details from employees;
Use q operator and write down “yea”
select firstname|| q’{yea] || managers as “Managers” from employees;
Display all rows from employees
select department_id * from employees;
Display unique elements
select DISTINT department_id from employees;
What does Describe do?
Displays the structure of a table
Select from employees where last_name is nilima.
and avoid that common mistake
select last_name
from employees
where
last_name=”nilima”;
Select from employees where salary is less than 300, more than 300, between 200-800
select salary from employees
where salary BETWEEN 200 AND 800;
select salary from employees where salary <=300;
Select names that begin with like “anychari”
select firstname from employees where firstname like ‘_i%’;
How to find null manager id from employees?
select manager_id from employees where manager_id IS NULL;
select from employees where salary is greater than 1000 and job_id is has the word “man” so IT_MAN
select manager_id from employees where
salary>=1000
AND
job_id LIKE ‘%MAN%’;
select from employees where salary is greater than 1000 or job_id is has the word “man” so IT_MAN
select manager_id from employees where
salary>=1000
or
job_id LIKE ‘%MAN%’;
What is the rule of precedence AND, OR and NOT
NOT
AND
OR
how to sort in descending order
select firstname from employees
ORDER By date desc;
Name function that changes to upper, lower and initcap
UPPER(“nilima”); NILIMA
LOWER(“manandhar”); manandhar
INITCAP(“nilima maandhar”);
Nilima Manandhar
Use lower in sql query
Select last_name from employees where LOWER(first_name) = ‘manandhar’;
How do you concat string?
CONCAT(‘hello’, ‘world’);
How to find length,
I have Hello World.
I want only Hello
get rid of h from hellow
LENGTH(‘HELLOWORLD’);
SUBSTR(‘HELLOWORLD’, 1 ,5);
TRIM(‘H’ from ‘hellow’)
What is the default date?
dd-MON-YY
What does sysdate return?
it returns date and time
select sysdate
from dual;
how to convert character, numbers and date?
to_char
to_date
to_number