SQL PHP HTML ASP JavaScript articles and free scripts to download

Subqueries in SQL

Sub quires are easy to understand and can be developed by using simple quires. These queries will have two parts , one is inner queries or inner select and outer queries or outer select.

These queries are easy to develop and most of the time preferred over complex joins.

There are some restriction in using sub queries. We cant modify the structure of a table by using sub query.

Let us start with some examples by using different types of queries using various sql commands.

select * from student where name Like (Select name from student where mark =86)

not in

select * from student where class not in (Select distinct(class) from student)

This query will return if any record is there where class data is not there.

By using ANY

select * from student where class = any (Select distinct(class) from student)

We will get all the records as we don't have any blank class data

select * from student where mark = (Select max(mark) from student)

The above query will return the details of the student who got maximum mark. This query will also work if there are two students with same maximum mark. But if we use only Max command then we will get only one record.

Not In

select * from student where class not in (Select max(mark) from student where class= any (select distinct class from student)) .

Dowload the sql dump of our student table


please can you post more subqueries examples to retrieve data from more than one table.
How to put a total at the bottom of a detailed report.
for example query database
Select product_code,description,net_sales from tablex

how do you put a total at the end of the report below column net_sales.
Post Comment This is for short comments only. Use the forum for more discussions.
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
For Email Newsletters you can trust

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer