UNION

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

UNION

David Niklas
# SELECT * FROM processors UNION SELECT * FROM storage;
Error: SELECTs to the left and right do not have the same number of
result columns.

All tables that I created in my database have differing column names,
values, and amounts of columns with the noted exception of the one
column which is common (board). I've no idea what to do now.

Why is this an error?

Thank you,
David
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: UNION

Stephen Chrzanowski
The error says it.  You need to have the same number of columns/fields.
For example, this would throw an error if processors had 3 fields and
storage had 4.  I don't think the names of the fields are important, as
it'll use whatever is defined in the first SELECT.

On Tue, Feb 28, 2017 at 8:40 PM, <[hidden email]> wrote:

> # SELECT * FROM processors UNION SELECT * FROM storage;
> Error: SELECTs to the left and right do not have the same number of
> result columns.
>
> All tables that I created in my database have differing column names,
> values, and amounts of columns with the noted exception of the one
> column which is common (board). I've no idea what to do now.
>
> Why is this an error?
>
> Thank you,
> David
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: UNION

J Decker
In reply to this post by David Niklas
On Tue, Feb 28, 2017 at 5:40 PM, <[hidden email]> wrote:

> # SELECT * FROM processors UNION SELECT * FROM storage;
> Error: SELECTs to the left and right do not have the same number of
> result columns.
>
> All tables that I created in my database have differing column names,
> values, and amounts of columns with the noted exception of the one
> column which is common (board). I've no idea what to do now.
>
> Why is this an error?
>

1   6770
2  3770

1  samsung 960   250G
2  seagate            5T
3

what should it use for fields, if the query first encounters 2 columns, and
starts allocating rows for it, then runs into data with 3, then it shouln't
just drop some arbitrary data, so it throws an error.
If you want them really to merge... on the first select *,"nothing" from X
untion select * from Y
(I think sqlite allows * as first or last argument)
or sepcifically name some number from X and the same number from Y and
it'll put them together....
Whether that actually has any meaning is up to the application....





>
> Thank you,
> David
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: UNION

Hick Gunter
In reply to this post by David Niklas
You are literally mixing apples and oranges without creating a superclass "fruit" that contains a field to tell them apart and a set of attributes (=fields) merged from the attributes of the component tables.

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:[hidden email]] Im Auftrag von [hidden email]
Gesendet: Mittwoch, 01. März 2017 02:40
An: [hidden email]
Betreff: [sqlite] UNION

# SELECT * FROM processors UNION SELECT * FROM storage;
Error: SELECTs to the left and right do not have the same number of result columns.

All tables that I created in my database have differing column names, values, and amounts of columns with the noted exception of the one column which is common (board). I've no idea what to do now.

Why is this an error?

Thank you,
David
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: [hidden email]

This communication (including any attachments) is intended for the use of the intended recipient(s) only and may contain information that is confidential, privileged or legally protected. Any unauthorized use or dissemination of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender by return e-mail message and delete all copies of the original communication. Thank you for your cooperation.


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: UNION

R Smith
In reply to this post by David Niklas

On 2017/03/01 3:40 AM, [hidden email] wrote:
> # SELECT * FROM processors UNION SELECT * FROM storage;
> Error: SELECTs to the left and right do not have the same number of
> result columns.
>
> All tables that I created in my database have differing column names,
> values, and amounts of columns with the noted exception of the one
> column which is common (board). I've no idea what to do now.
>
> Why is this an error?

I think that perhaps you are new to SQL and other replies assumed you
simply wanted what you wrote. I could be wrong, but just in case, here
are my suggestions:

Perhaps what you would rather like to do is JOIN these tables and not
UNION them?

Do you wish to match /every/ processor with /every/ board?
In this case, the statement should read: (Warning: this could produced
excessively long listings)
SELECT * FROM processors, storage;

Do you wish to match only processors and storage that fit on the same
boards?
In this case the statement might read something like:
SELECT *
FROM processors
   JOIN storage USING board
;

Do you wish to list /all/ processors and add the storage options for the
same board /if/ there are any?
In this case the statement might read something like:
SELECT *
   FROM processors
   LEFT JOIN storage ON storage.board = processors.board
;

As you can see, lots of different things can be achieved. A quick course
in SQL via perhaps W3Schools will teach all these in a few hours.

Cheers,
Ryan

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: UNION

jose isaias cabrera-3
Ryan,

I just want to thank you for your kindness and display of goodwill to
mankind.  This is a great response.  I even learned something from this
post.  Thanks so much for your responses.  There are others like us in
this group that love to learn and your posts always are well received.
Thanks.  In Spanish we say, "muchas gracias."

josé

On 2017-03-01 09:51, R Smith wrote:

> On 2017/03/01 3:40 AM, [hidden email] wrote:
>
>> # SELECT * FROM processors UNION SELECT * FROM storage;
>> Error: SELECTs to the left and right do not have the same number of
>> result columns.
>>
>> All tables that I created in my database have differing column names,
>> values, and amounts of columns with the noted exception of the one
>> column which is common (board). I've no idea what to do now.
>>
>> Why is this an error?
>
> I think that perhaps you are new to SQL and other replies assumed you simply wanted what you wrote. I could be wrong, but just in case, here are my suggestions:
>
> Perhaps what you would rather like to do is JOIN these tables and not UNION them?
>
> Do you wish to match /every/ processor with /every/ board?
> In this case, the statement should read: (Warning: this could produced excessively long listings)
> SELECT * FROM processors, storage;
>
> Do you wish to match only processors and storage that fit on the same boards?
> In this case the statement might read something like:
> SELECT *
> FROM processors
> JOIN storage USING board
> ;
>
> Do you wish to list /all/ processors and add the storage options for the same board /if/ there are any?
> In this case the statement might read something like:
> SELECT *
> FROM processors
> LEFT JOIN storage ON storage.board = processors.board
> ;
>
> As you can see, lots of different things can be achieved. A quick course in SQL via perhaps W3Schools will teach all these in a few hours.
>
> Cheers,
> Ryan
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: UNION

Don V Nielsen
Might I suggest: https://www.w3schools.com/sql/

dvn

On 03/01/2017 09:02 AM, jose isaias cabrera wrote:

> Ryan,
>
> I just want to thank you for your kindness and display of goodwill to
> mankind.  This is a great response.  I even learned something from this
> post.  Thanks so much for your responses.  There are others like us in
> this group that love to learn and your posts always are well received.
> Thanks.  In Spanish we say, "muchas gracias."
>
> josé
>
> On 2017-03-01 09:51, R Smith wrote:
>
>> On 2017/03/01 3:40 AM, [hidden email] wrote:
>>
>>> # SELECT * FROM processors UNION SELECT * FROM storage;
>>> Error: SELECTs to the left and right do not have the same number of
>>> result columns.
>>>
>>> All tables that I created in my database have differing column names,
>>> values, and amounts of columns with the noted exception of the one
>>> column which is common (board). I've no idea what to do now.
>>>
>>> Why is this an error?
>> I think that perhaps you are new to SQL and other replies assumed you simply wanted what you wrote. I could be wrong, but just in case, here are my suggestions:
>>
>> Perhaps what you would rather like to do is JOIN these tables and not UNION them?
>>
>> Do you wish to match /every/ processor with /every/ board?
>> In this case, the statement should read: (Warning: this could produced excessively long listings)
>> SELECT * FROM processors, storage;
>>
>> Do you wish to match only processors and storage that fit on the same boards?
>> In this case the statement might read something like:
>> SELECT *
>> FROM processors
>> JOIN storage USING board
>> ;
>>
>> Do you wish to list /all/ processors and add the storage options for the same board /if/ there are any?
>> In this case the statement might read something like:
>> SELECT *
>> FROM processors
>> LEFT JOIN storage ON storage.board = processors.board
>> ;
>>
>> As you can see, lots of different things can be achieved. A quick course in SQL via perhaps W3Schools will teach all these in a few hours.
>>
>> Cheers,
>> Ryan
>>
>> _______________________________________________
>> sqlite-users mailing list
>> [hidden email]
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: UNION

jose isaias cabrera-3

Thanks, Don.

-----Original Message-----
From: don v nielsen
Sent: Friday, March 3, 2017 3:21 PM
To: SQLite mailing list
Subject: Re: [sqlite] UNION

Might I suggest: https://www.w3schools.com/sql/

dvn

On 03/01/2017 09:02 AM, jose isaias cabrera wrote:

> Ryan,
>
> I just want to thank you for your kindness and display of goodwill to
> mankind.  This is a great response.  I even learned something from this
> post.  Thanks so much for your responses.  There are others like us in
> this group that love to learn and your posts always are well received.
> Thanks.  In Spanish we say, "muchas gracias."
>
> josé
>
> On 2017-03-01 09:51, R Smith wrote:
>
>> On 2017/03/01 3:40 AM, [hidden email] wrote:
>>
>>> # SELECT * FROM processors UNION SELECT * FROM storage;
>>> Error: SELECTs to the left and right do not have the same number of
>>> result columns.
>>>
>>> All tables that I created in my database have differing column names,
>>> values, and amounts of columns with the noted exception of the one
>>> column which is common (board). I've no idea what to do now.
>>>
>>> Why is this an error?
>> I think that perhaps you are new to SQL and other replies assumed you
>> simply wanted what you wrote. I could be wrong, but just in case, here
>> are my suggestions:
>>
>> Perhaps what you would rather like to do is JOIN these tables and not
>> UNION them?
>>
>> Do you wish to match /every/ processor with /every/ board?
>> In this case, the statement should read: (Warning: this could produced
>> excessively long listings)
>> SELECT * FROM processors, storage;
>>
>> Do you wish to match only processors and storage that fit on the same
>> boards?
>> In this case the statement might read something like:
>> SELECT *
>> FROM processors
>> JOIN storage USING board
>> ;
>>
>> Do you wish to list /all/ processors and add the storage options for the
>> same board /if/ there are any?
>> In this case the statement might read something like:
>> SELECT *
>> FROM processors
>> LEFT JOIN storage ON storage.board = processors.board
>> ;
>>
>> As you can see, lots of different things can be achieved. A quick course
>> in SQL via perhaps W3Schools will teach all these in a few hours.
>>
>> Cheers,
>> Ryan
>>
>> _______________________________________________
>> sqlite-users mailing list
>> [hidden email]
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users 

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users