Tuesday, November 17th, 2009 | Author: admin

Though I study with sql so often, I discovered something very important, today. That is the big difference between subqueries and join statements.
I have two tables named COMPANY and WORK_EXPERIENCE. In Company table there are company_id, company_name, company_country columns and in work_experience table there are id, company_id, employee_id and quit_date columns. So here what I’m trying to do is list all the companies names and the countries where they are in. Also list the number of employees that work in that company beside the name of the company in brackets. Like,
SQL1

So writing join statement like this:
SELECT dbo.ProperCase([company_name]) + ‘ (’ + cast(count(work_experience.id) as varchar) + ‘)’ COMPANY, COUNTRY_NAME
FROM [COMPANY]
INNER JOIN COUNTRY ON COMPANY.country_id = COUNTRY.country_id
LEFT JOIN WORK_EXPERIENCE ON COMPANY.company_id = WORK_EXPERIENCE.company_id
WHERE quit_date is null
group by COUNTRY_NAME

will bring our list but with an exception. If all rows related to one company in work_experience table have all values different than null in quit_date column, that company won’t be seen in the list. Because that is not what we want we can deal with this complication using subqueries.

SELECT COMPANY_NAME + ‘ (’ +
(select cast(count(WORK_EXPERIENCE.ID) as varchar) from WORK_EXPERIENCE WHERE
WORK_EXPERIENCE.company_id = COMPANY.company_id and quit_date is null) + ‘)’ COMPANY, country_name
FROM [COMPANY]
INNER JOIN COUNTRY ON COMPANY.country_id = COUNTRY.country_id

And the main idea is explaining in  :
AllInterview.com
Majorly subqueries run independently and result of the
subquery used in the outer query(other than corelated subquery).
And in case of join a query only give the result when the
joining condition gets satisfied.

Category: About  | Leave a Comment
Monday, December 29th, 2008 | Author: admin

Programcı olmaya karar verdiğim andan itibaren, her öğrendiğimi not defterime yazmaya başlamıştım. Bu notlarla bir site oluşturabilirdim tabii ama bunu yapacak vakit bulamıyordum. Mesleğe yeni başlamıştım, bir taraftan öğreniyordum bir taraftan çalışıyordum. Böylece meslekte 1.5 seneyi geride bıraktım. Artık notlarımı paylaşmamın tam zamanıydı. Bu aslında başta benim fikrim değildi. Bana bu mesleği kazandıran, bu hayatta kalabilmem için bana en değerli armağanlardan birini veren en değerli hocamın, meslektaşımın, yani babamın, fikir vermesi ve yönlendirmesi sonucu not defterimi sizlerle paylaşmaya karar verdim. Sırası gelmişken çok sevdiğim babama buradan çok teşekkür etmek istiyorum. Onun sayesinde buralara geldim. Sonsuz teşekkürler babacığım. Ve anneme sonsuz sabrı, yoğun çalışmalar esnasında evdeki her işe tek başına koştuğu ve babamla çalışmalarımız arasında karnımız acıktığında bize her zaman hazırladığı eşsiz lezzetli yemekleri için çok çok teşekkür etmek istiyorum. Son olarak da sevgili eşime ve ağabeyime, bana her zaman destek verdikleri için çok teşekkür ediyorum. İyiki varsınız.

Category: About  | Leave a Comment
Friday, December 05th, 2008 | Author: admin

I began to take notes, the moment that i decided to be a programmer. I wanted to make a site with these notes but I couldn’t find the time to do this because I was new in my career. I was working and learning at the same time. I’ve been working for 1.5 years in this job. Now it is the time to share my notes. This was not my idea, in the beginning. I started to make this site with my notes because someone gave me this idea. He is the one who is my precious teacher, my colleague, my father. He taught me everything which i know now. By the way i want to thank my dear father here. Thank you so much, daddy. And i want to thank my mother for her endless patience, doing all the job in the home when we were hard working and for all those delicious foods when we were hungry. At last i want to thank my dear husband and my brother for their support, everytime.

Category: About  | One Comment