Subqueries
Describe the types of problems that subqueries can solve.
First, it can also be used to join tables. Also, there are cases where the only way to correlate two tables is through a subquery. The ability to generate a query based on the condition of changing data that is located in another table.
Define subqueries.
A subquery is a SELECT query that returns a single value and is nested inside a SELECT, INSERT, UPDATE, or DELETE statement, or inside another subquery. A subquery can be used anywhere an expression is allowed. A subquery is also called an inner query or inner select, while the statement containing a subquery is also called an outer query or outer select.
It is possible to embed a SQL statement within another. When this is done on the WHERE or the HAVING statements, we have a subquery construct. What is subquery useful for? First, it can also be used to join tables. Also, there are cases where the only way to correlate two tables is through a subquery.
List the types of subqueries.
- WHERE EXISTS and WHERE NOT EXISTS
- WHERE IN and WHERE NOT IN
Write single-row and multiple-row subqueries.
/*Single-Row Column Subqueries*/
select * from person where exists (select employees from department);
select first_name, last_name, email
from users
where exists
(select top 5 from student where student.last_name = person.last_name;
/*Multiple-Column Subquery*/
select member from relatives where name in
(select * from foreign_relatives where lastname like '%R');
Describe and explain the behavior of subqueries when NULL values are retrieved.
When using NOT IN, in case the subquery returns a NULL no rows are selected for the main query , this is different from IN in which case if a NULL value is returned no special effect takes place.
When using NOT EXISTS if the subquery returns NULL (no rows selected) the main query will return its rows accordingly, and viceversa if the NOT EXISTS subquery returns at least one row then the main query will return no rows selected.
In the case of EXISTS if the subquery returns at least on row the main query returns its values accordingly, and vice versa if the EXISTS subquery returns NULL (no rows selected) then the main query will return no rows selected.
Write subqueries in the FROM clause.
select first_name, last_name, phone_number, age from person where female in
(select * from person where age > 21 );
home |
archives |
about me |
faq |
my resume |
you tube |
pics |
site map |
More...
ASP.Net |
Get State By Zip Code, VB.Net |
Editing an XML Document, VB.Net |
Accessing an XML Document, VB.Net |
Salary Bi-Directional Scrollable DataGrid C# |
State Bi-Directional Scrollable DataGrid C# |
IEWebControls - Microsoft's Way |
IEWebControls - My Way |
IEWebControls - MultiPage |
Multipage code |
IE WebControls - TabStrip |
TabStrip |
IEWebControls - Toolbar |
Toolbar code |
IEWebControls - Treeview |
Treeview code |
IEWebControls - Treeview Bound |
Treeview Bound code |
IEWebControls - Tree |
Tree code |
Fibonacci Numbers Demo |
Magic Numbers Demo |
Toolbar XML |
Toolbar XSL |
JavaScript |
Dynamic Form Size Counter |
Interest Calculator |
Get the Browser Type |
Cascading Menus |
More Cascading Menus |
Change Fonts through JavaScript and CSS |
JavaScript Dynamic Clock |
Copy Radio Button value to a Textbox |
JavaScript Dropdown State Textbox Search |
JavaScript Last Updated the Document |
Dynamic JavaScript Date Dropdown box |
JavaScript Code Decryptor Encryptor |
JavaScript Code Decryptor Encryptor |
Dynamic Form Field Character Size Checker set at 2000 varchar |
JavaScript MouseOver Hidden Messages |
JavaScript Dropdown list Search: value sent to QueryString |
JavaScript DDL Values Listbox to Listbox: IE, Moz |
JavaScript Country Filter Dropdown list Search form with Regular Expressions |
Scrolling JavaScript Marquee |
Another Calculator |
JavaScript Form Validation with Regular Expressions: complete |
JavaScript Link Selector from a Dropdown Menu |
Nice Dynamic Javascript Panels for searching and so forth |
JavaScript Dynamic Table Sorter |
JavaScript / HTML / HTML Component Text Highlighter for Internet Explorer and Gecko aka Mozill Firefox, AOL, and Netscape |
sql |
Normalization |
First Normal Form |
Second Normal Form |
Third Normal Form |
Fourth and Fifth Normal Form |
Inner Join |
Outer Join |
SQL Server 2000 versus Access 2002 |
Stored Procedure |
oracle |
Basic SQL Select |
Execute SELECT statement |
SQL statements and iSQL*Plus |
Restricting and Sorting Data |
Limit the rows |
Sort the rows retrieved by a query |
Single-Row Functions |
Various SQL Functions |
Character, number, and Date functions |
Use conversion functions |
Displaying Data from Multiple Tables |
Write SELECT statements to access data from more than one table using equality and nonequality joins |
View data Outer Joins |
Join a table to itself |
Aggregating Data |
Identify Group Functions |
Use Group Functions |
Group data GROUP BY |
HAVING clause |
Subqueries |
Problems that subqueries can solve |
Define subqueries |
List the types of subqueries |
Write single-row and multiple-row subqueries |
Output with iSQL*Plus |
Substitution Variable |
Readable output |
Create and execute script files |
Manipulating Data |
Describe each DML statement |
Insert rows into a table |
Update rows in a table |
Delete rows from a table |
Merge rows in a table |
Control transactions |
Creating and Managing Tables |
Main database objects |
Create tables |
Datatypes specifying column definition |
Alter table definitions |
Drop, rename and truncate tables |
Including Constraints |
Describe constraints |
Create and maintain constraints |
Creating Views |
Describe a view |
Create, alter the definition, and drop a view |
Retrieve data through a view |
Insert, update and delete data through a view |
Creating Other Database Objects |
Create, maintain and use sequences |
Create and maintain indexes |
Create private and public synonyms |
java |
City Planner |
CPU Scheduler |
Acme House System |
Number Searcher |
Password |
Producer Consumer |
Producer Consumer |
Producer Consumer No Buffer |
Producer Consumer Buffer 100 |
XML |
001.xml |
access_vs_sql.xml |
access_vs_sql.xsl |
admin |
admin |
arearate.htm |
arearate.xml |
arearate.xsd |
arearate.xsl |
arearate.xsx |
aspnet.xml |
aspnet.xsl |
aspnetbooks |
behave.htc |
behavior.htm |
bloglinks.xsl |
BottomLinks |
BUILDING.xml |
BUILDING.xsd |
Categories.xml |
cd_catalog.xml |
cdcatalog.xml |
cdcatalog.xsl |
cdcatalog_ |
cdcatalog |
cdcatalog_if |
cdcatalog_if |
cdcatalog |
cdcatalog |
cdcatalog |
Celebs.xml |
Celebs.xsl |
cities.txt |
cities_world.txt |
comment.htm |
comment.xml |
comment.xsd |
comment.xsl |
comment.xsx |
Contact.xml |
contact.xsl |
Contents.xml |
Contents.xslt |
COURSE.xml |
COURSE.xsd |
cursor_types.htm |
data_island.htm |
dispBooks.xsl |
dotnet.xml |
EditRecord.xml |
entire.xml |
entire.xsl |
ExtraLinks.xml |
ExtraLinks.xsl |
FACULTY.xml |
FACULTY.xsd |
FileName.xml |
FileName.xsd |
filesystem |
gakenheimer |
gakenheimer |
guestbook.xml |
home.xml |
home.xsd |
HTML Entities |
IS_QUALIFIED |
IS_QUALIFIED |
IS_REGISTERED |
IS_REGISTERED |
Java |
javascript |
javascript |
js.xml |
level1.xml |
LOGIN.xml |
LOGIN.xsd |
main.xsl |
MainLinks |
MainLinks |
MAJOR.xml |
MAJOR.xsd |
na_cities.xml |
Oracle |
OtherStuff |
OtherStuff |
people.xml |
PERSON.xsd |
RECORD.xsd |
rss.xml |
rss.xsl |
samples.xml |
SCHEDULE.xml |
SCHEDULE.xsd |
site.xml |
site.xsd |
sql.xml |
sql.xsl |
SS_table |
SS_table |
State.xml |
State.xsd |
states.htm |
states.xml |
states_move.htm |
states_move2.htm |
STUDENT.xsd |
TITLE.xml |
TITLE.xsd |
TopLinks.xsl |
updatedcontact |
world_cities.xml |
xmllinks.htm |
xmllinks.xml |
Algorithms |
Backjumping Algorithm |
Barnes-hut Algorithm |
Las Vegas and Monte Carlo Algorithm |
DBMS |
developer a database management system |
Downloads Directory |
balderdash |
content links |
CPUScheduler |
cheers |
CityPlanner |
Concat Strings |
Old Formal Resume |
joe resume .doc |
joe resume .txt |
Joseph Gakenheimer Resume .doc |
Knapsack |
My Shopping Cart Servlet |
NumberSearcher |
PasswordChecker |
SchoolSystem |
Stored Procedures |
Flash |
animals |
clock 0 |
clock 1 |
clock 2 |
clock 3 |
clock 4 |
clock 5 |
case 5 |
form |
hyperlink |
readymed |
snow |
HTML Templates |
calendar |
freud |
readymed |
excel |
old site template |
venus template |
Java |
Coming Soon |
JSP Research |
JSP Versus ASP |
J2EE Versus ASP.Net |
J2EE Versus ASP.Net Components |
MIS Windows 200 |
Action Plan - Active Directory Services |
Active Directory Services |
Challenges IS |
Monitoring Tools and Improvement |
Network Printing Environment |
An Overview of NTFS |
Proposal for Outsourcing Systems and Software Maintenance |
Hardware User Needs |
Windows 2000 Keypoints |
Operating Systems |
History of Operating Systems |
Operating System Questions |
Operating System Terms |
Clustering |
Open Source Acceptance |
Networking |
The Secure Socket Layer Review |
Network Design Proposal |
Exam 1 Review |
Exam 2 Review |
Software Engineering |
DinnerWare Software Design |
DinnerWare Software .doc |
DinnerWare Software .ppt |
Home |
Home |
About Me |
Archives |
FAQ |
My Resume |
My Portfolio |
Pics |
Site Map |
Updated: July 30, 2005; Joe Gakenheimer
© joegakenheimer.com