Understanding SQL query of division

| August 29, 2012 | 5 Comments

Writing SQL query for division has always been a tricky thing to do for beginners. Recently I was conducting a Database Systems course (summer 2012 Semester FAST Lahore) and prepared a short video tutorial on this topic. Here is a very short and simple example to write a SQL query of division.

create table R (A int, B int)
insert into R values(1,1)
insert into R values(2,1)
insert into R values(3,1)
insert into R values(1,3) 

create table S (A int)
insert into S values(1)
insert into S values(2)
insert into S values(3) 

Select * From R
Select * From S

-- R / S
Select distinct B from R as C
where not exists (
select A from S except
select A from R as CC where CC.B =C.B)

You can also download and have a look at the following video tutorial to understand this query.
Video Tutorial Youtube
Video Totorial Download

Category: SQL

Comments (5)

Trackback URL | Comments RSS Feed

  1. Asif Noor says:

    I think it is good idea to post video tutorial and putting source code on techipost because learning from video is more direct and quick than reading the whole text.

    Good job @Umair…Keep it up.

  2. sarah says:

    Thanks for all the information, it was very helpful i really like that you are providing information on PHP and MYSQL with basic JAVASCRIPT,being enrolled in http://www.wiziq.com/course/5871-php-mysql-with-basic-javascript-integrated-course i was looking for such information online to assist me on php and mysql and your information helped me a lot. Thanks.

  3. Adil says:

    at the end cc.B=c.B
    it is R.B=R.B

    :S could not get it 🙁

    • Umair Ashraf says:

      @Adil. Yes you can join a table with its copy as well. You can join any table with its self as well based upon some conditions. Have you seen the video ? it explains how it works .

  4. christi parks says:

    Hello, i would like to ask that what is the benefits of sql training, what all topics should be covered and it is kinda bothering me … and has anyone studies from this course http://www.wiziq.com/course/125-comprehensive-introduction-to-sql of SQL tutorial online?? or tell me any other guidance…
    would really appreciate help… and Also i would like to thank for all the information you are providing on sql training.

Leave a Reply