Select with subselects

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
  

Poston Tue, 22 Jul 2008 1:01 pm

Hello guys, I'm with a doubt cruel, these days I saw a select pretty crazy and I'm trying to understand him but I came to the conclusion No, vocês me poderial planned step by step these two select ´ s?

Code: Select all
select nome, end, (select * from tab2) from tab1
Code: Select all
select nome, end from tab1, (select * from tab2)
I'm grateful!
carlos12
Location: rio

Poston Tue, 22 Jul 2008 1:16 pm

In the first case
Code: Select all
select nome, end, (select * from tab2) from tab1
you are showing the field name and end of tab1 and tab2 all fields of;

Code: Select all
select nome, end from tab1, (select * from tab2)
you are showing the field name and end of tab1 and transforming the select within the parentheses in a table where you can use the fields in the where and select to present ...


In the examples that you put the only difference is that the second is not showing the information of the tab2, if u had put:
Code: Select all
select nome, end, tab2.* from tab1, (select * from tab2)
might as well!!

Hugs:-
jessica.ff
Location: Gravataí - RS

ninguém é tão sabio que não tenha a aprender, e nem tão ignorante que não tenha a ensinar.

Poston Tue, 22 Jul 2008 1:29 pm

Jessica in this second case I have an alias to tab2. to get up there?
carlos12
Location: rio

Poston Tue, 22 Jul 2008 1:43 pm

Yes you have to have an alias, for example:
Code: Select all
Select t1.nome, t1.end, total.salario
  from tab1 t1
         ,(select salario
             from tab2
           where total > 1) total
where t1.nome like 'A%'
jessica.ff
Location: Gravataí - RS

ninguém é tão sabio que não tenha a aprender, e nem tão ignorante que não tenha a ensinar.

Poston Tue, 22 Jul 2008 1:46 pm

vish my ... the select you get for him anywhere he saw more = D not occur problems ... it's always nice to you put a join them não é? .... example
Code: Select all
select em.*, (select dname from dept dp where dp.deptno = em.deptno) dname from emp em
/
that is the same thing that
Code: Select all
select em.*, d.dname from emp em, dept d where d.deptno = em.deptno
/
só Chi with the second case was a join in the correct manner the Bank played with a sort-merge and lá feiz an order by automatically and the first case was the same thing .... just not ordered automatically.
gokden
Location: Ribeirão Preto - SP

Lucas de Souza

OCA Developer
Analista de sistemas

Poston Tue, 22 Jul 2008 3:44 pm

Guys valeu even made several tests and gave aqui have a good base brigadão all: wink:
carlos12
Location: rio



Return to SQL

Who is online

Users browsing this forum: Bing [Bot] and 5 guests