Combined Select Statement

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

Combined Select Statement

jic

Greetings!

I have two tables:

CREATE TABLE X
                    (
                        login primary key,
                        Name,
                        Password,
                        ...,
                        ProjOwned
                    );


CREATE TABLE Y
                    (
                        login primary key,
                        Internal,
                        ...,
                        Place
                    );


What I would like to do is to create a select statement that will bring,

X.Login,X.Name,Y.Internal

as the result in one row.  I have a select statement with union but it comes
in two rows, plus union wants me to pair the selection.  I would like to
have it in one row.

Any help would be greatly appreciated.

thanks,

josé

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

Re: Combined Select Statement

Igor Tandetnik
jose isaias cabrera <[hidden email]>
wrote:

> I have two tables:
>
> CREATE TABLE X
>                     (
>                         login primary key,
>                         Name,
>                         Password,
>                         ...,
>                         ProjOwned
>                     );
>
>
> CREATE TABLE Y
>                     (
>                         login primary key,
>                         Internal,
>                         ...,
>                         Place
>                     );
>
>
> What I would like to do is to create a select statement that will
> bring,
>
> X.Login,X.Name,Y.Internal

Is there some relationship between the two tables? Which rows from each
do you want to match up, to form a single row in the resultset?

Igor Tandetnik



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

Re: Combined Select Statement

BareFeetWare
In reply to this post by jic
Hi José,

> I have two tables:
>
> CREATE TABLE X
>                    (
>                        login primary key,
>                        Name,
>                        Password,
>                        ...,
>                        ProjOwned
>                    );
>
>
> CREATE TABLE Y
>                    (
>                        login primary key,
>                        Internal,
>                        ...,
>                        Place
>                    );
>
>
> What I would like to do is to create a select statement that will  
> bring,
>
> X.Login,X.Name,Y.Internal
>
> as the result in one row.

Assuming that the tables are related by the "Login" column/field, then  
you to join then, such as:

select X.Login, X.Name, Y.Internal from X left join Y on X.Login =  
Y.Login

Tom
BareFeet

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

Re: Combined Select Statement

jose isaias cabrera

thanks, BareFeet.  I will give this a try tomorrow.

Igor,

I tried to reply to your email, but somehow, I can not reply to newsgroup.
Weird.  But, the relationship is login.

thanks,

josé


----- Original Message -----
From: "BareFeet" <[hidden email]>
To: "General Discussion of SQLite Database" <[hidden email]>
Sent: Tuesday, October 28, 2008 6:43 PM
Subject: Re: [sqlite] Combined Select Statement


> Hi José,
>
>> I have two tables:
>>
>> CREATE TABLE X
>>                    (
>>                        login primary key,
>>                        Name,
>>                        Password,
>>                        ...,
>>                        ProjOwned
>>                    );
>>
>>
>> CREATE TABLE Y
>>                    (
>>                        login primary key,
>>                        Internal,
>>                        ...,
>>                        Place
>>                    );
>>
>>
>> What I would like to do is to create a select statement that will
>> bring,
>>
>> X.Login,X.Name,Y.Internal
>>
>> as the result in one row.
>
> Assuming that the tables are related by the "Login" column/field, then
> you to join then, such as:
>
> select X.Login, X.Name, Y.Internal from X left join Y on X.Login =
> Y.Login
>
> Tom
> BareFeet
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>

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

Re: Combined Select Statement

jic
In reply to this post by jic

thanks, BareFeet.  I will give this a try tomorrow.

Igor,

I tried to reply to your email, but somehow, I can not reply to newsgroup.
Weird.  But, the relationship is login.

 thanks,

 josé


> ----- Original Message -----
> From: "BareFeet" <[hidden email]>
> To: "General Discussion of SQLite Database" <[hidden email]>
> Sent: Tuesday, October 28, 2008 6:43 PM
> Subject: Re: [sqlite] Combined Select Statement
>
>
>> Hi José,
>>
>>> I have two tables:
>>>
>>> CREATE TABLE X
>>>                    (
>>>                        login primary key,
>>>                        Name,
>>>                        Password,
>>>                        ...,
>>>                        ProjOwned
>>>                    );
>>>
>>>
>>> CREATE TABLE Y
>>>                    (
>>>                        login primary key,
>>>                        Internal,
>>>                        ...,
>>>                        Place
>>>                    );
>>>
>>>
>>> What I would like to do is to create a select statement that will
>>> bring,
>>>
>>> X.Login,X.Name,Y.Internal
>>>
>>> as the result in one row.
>>
>> Assuming that the tables are related by the "Login" column/field, then
>> you to join then, such as:
>>
>> select X.Login, X.Name, Y.Internal from X left join Y on X.Login =
>> Y.Login
>>
>> Tom
>> BareFeet
>>
>> _______________________________________________
>> sqlite-users mailing list
>> [hidden email]
>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>>
>

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

Re: Combined Select Statement

Puneet Kishor-2
On 10/28/08, jose isaias cabrera <[hidden email]> wrote:
>
>  thanks, BareFeet.  I will give this a try tomorrow.
>
>  Igor,
>
>  I tried to reply to your email, but somehow, I can not reply to newsgroup.
>  Weird.  But, the relationship is login.

If the relationship is X.login = Y.login where each is a primary key
in the respective table then you should really reconsider the
structure of your db... they really should be one table.


>
>   thanks,
>
>   josé
>
>
>
>  > ----- Original Message -----
>  > From: "BareFeet" <[hidden email]>
>  > To: "General Discussion of SQLite Database" <[hidden email]>
>  > Sent: Tuesday, October 28, 2008 6:43 PM
>  > Subject: Re: [sqlite] Combined Select Statement
>  >
>  >
>  >> Hi José,
>  >>
>  >>> I have two tables:
>  >>>
>  >>> CREATE TABLE X
>  >>>                    (
>  >>>                        login primary key,
>  >>>                        Name,
>  >>>                        Password,
>  >>>                        ...,
>  >>>                        ProjOwned
>  >>>                    );
>  >>>
>  >>>
>  >>> CREATE TABLE Y
>  >>>                    (
>  >>>                        login primary key,
>  >>>                        Internal,
>  >>>                        ...,
>  >>>                        Place
>  >>>                    );
>  >>>
>  >>>
>  >>> What I would like to do is to create a select statement that will
>  >>> bring,
>  >>>
>  >>> X.Login,X.Name,Y.Internal
>  >>>
>  >>> as the result in one row.
>  >>
>  >> Assuming that the tables are related by the "Login" column/field, then
>  >> you to join then, such as:
>  >>
>  >> select X.Login, X.Name, Y.Internal from X left join Y on X.Login =
>  >> Y.Login
>  >>
>  >> Tom
>  >> BareFeet
>  >>
>  >> _______________________________________________
>  >> sqlite-users mailing list
>  >> [hidden email]
>  >> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>  >>
>  >
>
>  _______________________________________________
>  sqlite-users mailing list
>  [hidden email]
>  http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>


--
Puneet Kishor http://punkish.eidesis.org/
Nelson Institute for Environmental Studies http://www.nelson.wisc.edu/
Open Source Geospatial Foundation (OSGeo) http://www.osgeo.org/
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Combined Select Statement

BareFeetWare
In reply to:

> If the relationship is X.login = Y.login where each is a primary key
> in the respective table then you should really reconsider the
> structure of your db... they really should be one table.

That's only true if every record/row in table X has a corresponding  
record/row in table Y, with no null field/column values in either.  
However, if table Y only contains a matching record/row for some of  
the record/rows in table X, then separate tables is the correct way to  
go. It's a properly normalized database.

Tom
BareFeet

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

Re: Combined Select Statement

jic

> In reply to:
>
>> If the relationship is X.login = Y.login where each is a primary key
>> in the respective table then you should really reconsider the
>> structure of your db... they really should be one table.
>
> That's only true if every record/row in table X has a corresponding  
> record/row in table Y, with no null field/column values in either.  
> However, if table Y only contains a matching record/row for some of  
> the record/rows in table X, then separate tables is the correct way to  
> go. It's a properly normalized database.
>

And this is exactly the case.

thanks.

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