UNION ALL

Hi all, I am learning this function, and from all the examples i have seen, i cannot unfortunately get any to work.

Here is the Query

Set LandAndAir=oConn.Execute("SELECT * FROM enq_land,enq_land_items,supplier_status WHERE enq_land.land_ID=enq_land_items.land_ID AND land_process<>10 AND item_process<>10 AND enq_land.enq_ID="&Request.QueryString("enqview")&" AND supplier_land=land_process UNION ALL SELECT * FROM enq_air_sectors WHERE air_ID="&AirBookings("air_ID")&" AND sector_status<>10 ORDER BY sector_date,sector_deptime,land_indate,land_type")

Open in new window


Not sure where I am going wrong

Thanks in advance for your help
Graemewebber4technologiesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russ SuterSenior Software DeveloperCommented:
This is more of a SQL question than an ASP question. That being said let me try to help.

A union only works if both parts of the union statement have the same column definitions. That is to say they have the same number of columns and the respective data types are compatible.

While it is not a good idea to use the '*' selector in any SQL query it's especially not a good idea when using a UNION statement since you really can't tell what columns are being selected.
Graemewebber4technologiesAuthor Commented:
Ah that makes sense, is there something like UNION where i can display 2 tables with diff columns (in the tables there are similar tables)
Russ SuterSenior Software DeveloperCommented:
The only way to display two different column results would be with a join. You will then end up with a row that has a combination of columns from both tables. Alternately, if you must use a union you can somewhat coerce the two tables to have the same columns using something like this:

SELECT
  Id,
  Name,
  Description
FROM
  TABLE_A
UNION ALL
SELECT
  Id,
  Name,
  '' as [Description]
FROM
  TABLE_B

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Graemewebber4technologiesAuthor Commented:
I have been looking into JOIN today and it seems that is the way to go, cheers for all

Ill prob be posting JOIN soon :P
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.