SELECT CALCULATED

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

Poston Tue, 15 Jan 2008 12:14 pm

GUYS I HAVE A QUERY THAT BRINGS ME ALL CUSTOMERS NEED.
Code: Select all
SELECT CAMPO1, CAMPO2, CAMPO3

FROM VIEW1 V

WHERE

V.CAMPO1  between '1201' and '1207'
OK IT BRINGS CUSTOMERS RIGHT BUT NOW I NEED to KNOW IF THESE CUSTOMERS HAVE RECORDS in ANOTHER TABLE e.g. VIEW2 and WANT in ADDITION to THESE RECORDS HE BRING the OTHER RECORDS CONTAINED in the OTHER TABLE.

HOW CAN I DO THIS?
carlos12
Location: rio

Poston Tue, 15 Jan 2008 12:45 pm

I think exists is the best option for this situation, follows one example ...

Code: Select all
SELECT campo1, campo2, campo3
  FROM view1 v
WHERE v.campo1 BETWEEN '1201' AND '1207'
   AND EXISTS (SELECT 1
                 FROM view2 vd
                WHERE vd.campo1 = v.campo1)
   AND EXISTS (SELECT 1
                 FROM view3 vt
                WHERE vt.campo1 = v.campo1)


[]'s
Tineks
Location: Araraquara - SP

Cristiano (Tineks)
Araraquara - SP

Poston Thu, 17 Jan 2008 11:15 am

Hello, what you need I think is a union to get the data from another table see also:
Code: Select all
SELECT CAMPO1, CAMPO2, CAMPO3

FROM VIEW1 V

WHERE

V.CAMPO1  between '1201' and '1207'
union
SELECT CAMPO1, CAMPO2, CAMPO3

FROM VIEW2 V

WHERE

V.CAMPO1  between '1201' and '1207'

in this case will bring oa to data from another table, if necessary you can select out ordering the records from two tables.
TBou
Location: Campo Grande - MS

Thiago Bourscheidt
thiago.info@apoiorural.com.br
Analista de Sistemas



Return to SQL

Who is online

Users browsing this forum: No registered users and 4 guests