Question

In: Computer Science

​​​​​​Please give examples for my study guide, Thank You Be able to use the join syntax...

​​​​​​Please give examples for my study guide, Thank You

  • Be able to use the join syntax for queries, including outer joins.
  • Know how to rename tables and columns.
  • Know order by, asc, and desc, between, and not between.
  • Know how to use the SQL set operations of union, intersect, and except. Know how to use all with these.
  • Know how to do tuple comparison in queries.
  • Know how to use operators with nulls, and know the is null and is not null operators.
  • Be able to use the aggregate functions avg, count, min, max, and sum and know how to use them with group by and having.
  • Know how aggregation works with null values.
  • Know how to nest subqueries: in, not in, some, all, and exists. Know how to nest queries in the from clause. Be able to use the with clause. Be able to use scalar subqueries.
  • Know how to use correlation variables in subqueries.
  • Know how to use case in queries.
  • Know how to insert, delete, and update using subqueries.

Solutions

Expert Solution

1. Know how to rename tables and columns

SYNTAX:

  • FOR TABLE
ALTER TABLE table_name
RENAME TO new_table_name;
  • FOR COLUMN

IN ORACLE:-

ALTER TABLE table_name
RENAME COLUMN old_name TO new_name;

IN MySQL,MariaDB:-

ALTER TABLE table_name
CHANGE COLUMN old_name TO new_name;

Sample Table:

IPL

POSITION PLAYER POINTS
1 DHONI 23
2 KOHLI 21
3 KL RAHUL 20
4 ROHIT SHARMA 19

QUERY:

ALTER TABLE IPL RENAME COLUMN PLAYER TO CAPTAIN;

OUTPUT:

POSITION CAPTAIN AGE
1 MS DHONI 23
2 VIRAT KOHLI 21
3 KL RAHUL 20
4 ROHIT SHARMA 19

FOR TABLENAME:

QUERY:

ALTER TABLE IPL RENAME TO CAPTAIN_POINTS;

OUTPUT:

CAPTAIN_POINTS

ROLL_NO FIRST_NAME AGE
1 Ram 20
2 Abhi 21
3 Rahul 22
4 Tanu 19

2. Know order by, asc, and desc, between, and not between.

SYNTAX:

SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC | DESC;

EXAMPLE:

ID YOUTUBERS City PostalCode Country
1
COVID WUHAN 12209 CHINA
2 ELVISH YADAV GURUGRAM 122051 INDIA
3 TECHNICAL GURUJI ABU DHABI 05023 DUBAI
4
PEWDIEPIE NEW ORLEANS 12995 USA

QUERY:

SELECT * FROM Customers
ORDER BY Country;

OUTPUT:

ID YOUTUBERS City PostalCode Country
1
COVID WUHAN 12209 CHINA
2 TECHNICAL GURUJI ABU DHABI 05023 DUBAI
3 ELVISH YADAV GURUGRAM 122051 INDIA
4
PEWDIEPIE NEW ORLEANS 12995 USA

QUERY:

SELECT * FROM Customers
ORDER BY Country DESC;

OUTPUT:

ID YOUTUBERS City PostalCode Country
1
PEWDIEPIE NEW ORLEANS 12209 USA
2 ELVISH YADAV GURUGRAM 122051 INDIA
3 TECHNICAL GURUJI ABU DHABI 05023 DUBAI
4
COVID WUHAN 12209 CHINA

  • BETWEEN SYNTAX

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

  • NOT BETWEEN SYNTAX

SELECT column_name(s)
FROM table_name
WHERE column_name NOT BETWEEN value1 AND value2;

EXAMPLE:

ProductID ProductName SupplierID CategoryID Unit Price
1 Chais 1 1 10 boxes x 20 bags 18
2 Chang 1 1 24 - 12 oz bottles 19
3 Aniseed Syrup 1 2 12 - 550 ml bottles 10
4 Chef Anton's Cajun Seasoning 1 2 48 - 6 oz jars 22
5 Chef Anton's Gumbo Mix 1 2 36 boxes 21.35

QUERY-

SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;

OUTPUT:-

ProductID ProductName SupplierID CategoryID Unit Price
1 Chais 1 1 10 boxes x 20 bags 18
2 Chang 1 1 24 - 12 oz bottles 19
3 Aniseed Syrup 1 2 12 - 550 ml bottles 10
15 Genen Shouyu 6 2 24 - 250 ml bottles 15.5

NOT BETWEEN:

QUERY:

SELECT * FROM Products
WHERE Price NOT BETWEEN 10 AND 20;

OUTPUT:-

ProductID ProductName SupplierID CategoryID Unit Price
4 Chef Anton's Cajun Seasoning 2 2 48 - 6 oz jars 22
5 Chef Anton's Gumbo Mix 2 2 36 boxes 21.35
6 Grandma's Boysenberry Spread 3 2 12 - 8 oz jars 25
7 Uncle Bob's Organic Dried Pears 3 7 12 - 1 lb pkgs. 30
  • Know how to use the SQL set operations of union, intersect, and except.

FOR UNION:

SYNTAX-

SELECT * FROM TABLE1 
UNION
SELECT * FROM TABLE2;

EXAMPLE:

The TOPPLAYER table,

ID NAME
1 DHONI
2 KOHLI

The FLOPPLAYER table,

ID NAME
2 KOHLI
3 KL RAHUL

QUERY:

SELECT * FROM TOPPLAYER
UNION
SELECT * FROM FLOPPLAYER;

OUTPUT:

ID NAME
1 DHONI
2 KOHLI
3 KL RAHUL

FOR INTERSECT:

SYNTAX:

SELECT * FROM TABLE1
UNION
SELECT * FROM TABLE2;

EXAMPLE:

QUERY:

SELECT * FROM TOPPLAYER
INTERSECT
SELECT * FROM FLOPPLAYER;

OUTPUT:

ID NAME
2 KOHLI

FOR EXCEPT OR MINUS:

SYNTAX:

SELECT * FROM TABLE1
EXCEPT
SELECT * FROM TABLE2;

EXAMPLE:

QUERY:

SELECT * FROM TOPPLAYER 
MINUS
SELECT * FROM FLOPPLAYER;

OUTPUT:

ID NAME
1 DHONI
3 KL RAHUL
  • Know how to use all with these.

SYNTAX:

SELECT column_name(s)
FROM table_name
WHERE column_name operator ALL
(SELECT column_name FROM table_name WHERE condition);

EXAMPLE:

PLAYERPOINTS

PLAYERID PLAYERNAME TEAM POINTS
1 DHONI CSK 18
2 KOHLI RCB 19
3 R SHARMA MI 10
4 KL RAHUL KXIP 22

IPLPOINTS

TEAMID TEAMNAME PLAYERID POINTS
1 CSK 11 12
2 RCB 42 10
3 MI 72 5
4 KXIP 14 9

QUERY:

SELECT PLAYERNAME
FROM PLAYERPOINTS
WHERE TEAMID = ALL (SELECT TEAMID FROM IPLPOINTS WHERE POINTS= 10);

OUTPUT:

Number of Records: 0

PLAYERNAME

* WE ARE ONLY ALLOWED TO ANSWER FIRST FOUR PARTS*

SO. KINDLY SORRY,FOR OTHER REMAINING PARTS.


Related Solutions

This is my review study guide for my biology final can someone please answer them so...
This is my review study guide for my biology final can someone please answer them so i can study. Thank you Assuming only full-chromosome separations in meiosis, how many different genetic combinations are there for Kate and Jon’s offspring? Show an equation for calculating this and explain the math. The phenotype for cheater-gene expression is recessive. Kate was homozygous for the cheater gene mutation, and thus was very promiscuous with partners outside her relationship. Jon was homozygous too, but lacked...
PLEASE ANSWER QUESTIONS WITH ALL CALCULATIONS! WILL GIVE THUMBS UP ! THANK YOU ! 6. Use...
PLEASE ANSWER QUESTIONS WITH ALL CALCULATIONS! WILL GIVE THUMBS UP ! THANK YOU ! 6. Use the information below and the Two-stage Growth Model to find Axis Capital’s intrinsic value.  Forecast its cash flows from t+1 to t+3.  If its current price is $37.54, is it over or under valued? t t+1 t+2 t+3 t+4 Beta 0.80 ROE 0.09 0.08 0.08 0.08 DPO 0.37 0.34 0.34 0.34 Div $1.64
what are contextual features in a case study ? please give examples
what are contextual features in a case study ? please give examples
*Please answer all parts of the question. Thank you! Would you be able to kinematically analyze...
*Please answer all parts of the question. Thank you! Would you be able to kinematically analyze the entire body during a volleyball attack/spike? Could you provide the phases and within each phase, could you provide the plane of motion, axis of rotation(s), joints involved, joint type, muscle action, and muscle contraction type?
I need a scholarship essay for my nursing program. please and thank you.
I need a scholarship essay for my nursing program. please and thank you.
Using SAS programming Please include the syntax and output of the information: In a study of...
Using SAS programming Please include the syntax and output of the information: In a study of factors thought to be responsible for the adverse effects of smoking on human reproduction, cadmium level determinations (nanograms per gram) were made on placenta tissue of a sample of 14 mothers who were smokers and an independent random sample of 18 nonsmoking mothers. The results were as follows- Nonsmokers: 10.0, 8.4, 12.8, 25.0, 11.8, 9.8, 12.5, 15.4, 23.5, 9.4, 25.1, 19.5, 25.5, 9.8, 7.5,...
Using SAS programming Please include the syntax and output of the information: In a study of...
Using SAS programming Please include the syntax and output of the information: In a study of factors thought to be responsible for the adverse effects of smoking on human reproduction, cadmium level determinations (nanograms per gram) were made on placenta tissue of a sample of 14 mothers who were smokers and an independent random sample of 18 nonsmoking mothers. The results were as follows- Nonsmokers: 10.0, 8.4, 12.8, 25.0, 11.8, 9.8, 12.5, 15.4, 23.5, 9.4, 25.1, 19.5, 25.5, 9.8, 7.5,...
For acid woke up, when do we use H2O or H3O+. Please give example. Thank you.
For acid woke up, when do we use H2O or H3O+. Please give example. Thank you.
Please provide computation for each conversion and Don't use large/big values. Thank you! Give a value...
Please provide computation for each conversion and Don't use large/big values. Thank you! Give a value for each number system (decimal, binary, octal and hexa-decimal) then convert each value to each number system (example: given value is decimal, convert the given value to binary, octal and hexa-decimal and vice-versa).
Please solve A, B, and C. Please use excel. Please show work. Thank you. A. Use...
Please solve A, B, and C. Please use excel. Please show work. Thank you. A. Use the stocks of Apple, SAP, IBM, Oracle, and Amazon Download the historical data of weekly stock prices and S&P 500 index prices from year 2017-2019 on the website of yahoo finance and save it on an excel file. B. Use a different sheet to save the market adjusted prices of Apple, SAP, IBM, Oracle, and Amazon t and the index. For each stock, compute...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT