Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
UNION surprise
Message
De
23/02/2015 12:21:31
 
 
À
23/02/2015 12:02:54
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01615724
Message ID:
01615736
Vues:
35
>>UNION does not set any relations between queries, it only combines there results. I'm not sure why you would expect anything else.
>>
>>>I recently crashed when I tried:
>>>
>>>
>>>select intcolumn, charcolumn from tablea
>>>union all
>>>select charcolumn, intcolumn from tableb
>>>The message was that the data types couldn't be converted.
>>>
>>>Checking SQL help, I was surprised to learn that both the number of columns and the order of the columns have to match- column names don't seem to matter at all.
>>>
>>>
>>>So.. this UNION of all char columns doesn't crash :
>>>
>>>
>>>select sealnumber, customer from tablea
>>>union all
>>>select customer,sealnumber from tableb
>>>
>>>but the result is whacky.
>>>The sealnumber column contains sealnumbers from table A and customers from table B and
>>>the customer column contains customers from table A and sealnumbers from table B
>
>I was surprised that it ignores the column names in the second table and goes strictly by the position they occupy in the query.
>I only discovered it because of my sloppy typing.
>It really doesn't combine the queries in my mind now. It establishes a structure based on the first table and fits the second table into that structure based on order, regardless of columns names.
>That's OK, but it's not what I expected.
If only there was a SET DWIM ON command...
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform