SQL Flashcards

1
Q

How to select salary and add 300?

A

select salary, firstname, salary+300 from employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Use aliases for select firstname and say name

A

select first_name as FirstName from Employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Use aliases for select firstname and say name

A

select first_name as FirstName from Employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Concatenate firstname and lastname and alias as full name

A

select firstname||lastname as fullname from employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
Get this output for me:
"Nilima is a programmer"
and nilima = firstname
job = programmer
with alias
A

select firstname ||’is a ‘|| job as employee_details from employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Use q operator and write down “yea”

A

select firstname|| q’{yea] || managers as “Managers” from employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Display all rows from employees

A

select department_id * from employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Display unique elements

A

select DISTINT department_id from employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does Describe do?

A

Displays the structure of a table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Select from employees where last_name is nilima.

and avoid that common mistake

A

select last_name
from employees
where
last_name=”nilima”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Select from employees where salary is less than 300, more than 300, between 200-800

A

select salary from employees
where salary BETWEEN 200 AND 800;
select salary from employees where salary <=300;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Select names that begin with like “anychari”

A

select firstname from employees where firstname like ‘_i%’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to find null manager id from employees?

A

select manager_id from employees where manager_id IS NULL;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

select from employees where salary is greater than 1000 and job_id is has the word “man” so IT_MAN

A

select manager_id from employees where
salary>=1000
AND
job_id LIKE ‘%MAN%’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

select from employees where salary is greater than 1000 or job_id is has the word “man” so IT_MAN

A

select manager_id from employees where
salary>=1000
or
job_id LIKE ‘%MAN%’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the rule of precedence AND, OR and NOT

17
Q

how to sort in descending order

A

select firstname from employees

ORDER By date desc;

18
Q

Name function that changes to upper, lower and initcap

A

UPPER(“nilima”); NILIMA
LOWER(“manandhar”); manandhar
INITCAP(“nilima maandhar”);
Nilima Manandhar

19
Q

Use lower in sql query

A

Select last_name from employees where LOWER(first_name) = ‘manandhar’;

20
Q

How do you concat string?

A

CONCAT(‘hello’, ‘world’);

21
Q

How to find length,
I have Hello World.
I want only Hello
get rid of h from hellow

A

LENGTH(‘HELLOWORLD’);
SUBSTR(‘HELLOWORLD’, 1 ,5);
TRIM(‘H’ from ‘hellow’)

22
Q

What is the default date?

23
Q

What does sysdate return?

A

it returns date and time
select sysdate
from dual;

24
Q

how to convert character, numbers and date?

A

to_char
to_date
to_number

25
Name group functions
AVG, count, max, min, sum
26
when do you use group by?
if you have group functions and select department_id then department_id should be group by select avg(salary) from employees group by department_id;
27
``` Can you use where like this where AVG(salary)>300; ```
No that's why you use having? | Having(salary)>=300;
28
What is a natural join?
it is based on all columns in the two tables that have the same name. It selects rows from the two tables that have equal values in all matched columns