Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combining multiple select statement

Status
Not open for further replies.

Pgiegucz

IS-IT--Management
Feb 21, 2003
4
US
Is it possible to combine these select statements into one select statement???


select s.beginmileage, s.endmileage
from DTS_PoliceTriplog_tmp s
left join payRollLookup p
on s.PayrollNo=p.payrollNo
left join locationlookup l
on s.locationno=l.locationno
left join vehicllookup v
on s.vehicleNo=v.vehicleNo
where beginmileage = endmileage and directory = 'police Logs'

select s.calculatedmiles from DTS_PoliceTriplog_tmp s
where calculatedmiles < '0' and directory = 'police logs'

(select s.payrollno from DTS_PoliceTriplog_tmp s
where s.payrollno not in (select payrollno from qalookup) and directory = 'police logs')

(select s.locationno from DTS_PoliceTriplog_tmp s
where s.locationno not in (select locationno from locationlookup) and directory = 'police logs')

(select s.vehicleno from DTS_PoliceTriplog_tmp s
where s.vehicleNo not in (select vehicleNo from vehicllookup) and directory = 'police logs')
 
Use SQL UNION to combine row sets from different queries. There is a catch though. All queries in a union have to have the same number of columns with respective columns having the same type.
So if column 1 of query 1 has INTeger data type then column 1 of all queries in the union has to be INTeger type.

Example:
SELECT INT_ID, CHAR_FIELD FROM TABLE1
UNION
SELECT INT_ANOTHER_ID, CHAR_NAME FROM TABLE2

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top