dbTalk Databases Forums  

SQL Query

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss SQL Query in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
may_sapak1234@yahoo.com
 
Posts: n/a

Default SQL Query - 11-14-2007 , 11:14 PM






hi everyone. i'm new to sql server.

i have 2 tables. i want to return \all rows in both tables for each
row in table2. please refer to the following. sorry can't get my
thoughts across clearly.

thanks in advance

create table table1 (
c1 char(1),
c2 tinyint
)

insert into table1 values ( 'A', 1 )
insert into table1 values ( 'B', 2 )
insert into table1 values ( 'C', 3 )

create table table2 (
c1 char(1),
c2 tinyint
)

insert into table2 values ( 'D', 4 )
insert into table2 values ( 'E', 5 )

--return table1.*, table2.* from table1 for each row in table2

/*
table1 tabl1 table2 table2
c1 c2 c1 c2
A 1 D 4
B 2 D 4
C 3 D 4
A 1 E 5
B 2 E 5
C 3 E 5
*/

Reply With Quote
  #2  
Old   
Om
 
Posts: n/a

Default Re: SQL Query - 11-15-2007 , 03:22 AM






On Nov 15, 10:14 am, may_sapak1... (AT) yahoo (DOT) com wrote:
Quote:
hi everyone. i'm new to sql server.

i have 2 tables. i want to return \all rows in both tables for each
row in table2. please refer to the following. sorry can't get my
thoughts across clearly.

thanks in advance

create table table1 (
c1 char(1),
c2 tinyint
)

insert into table1 values ( 'A', 1 )
insert into table1 values ( 'B', 2 )
insert into table1 values ( 'C', 3 )

create table table2 (
c1 char(1),
c2 tinyint
)

insert into table2 values ( 'D', 4 )
insert into table2 values ( 'E', 5 )

--return table1.*, table2.* from table1 for each row in table2

/*
table1 tabl1 table2 table2
c1 c2 c1 c2
A 1 D 4
B 2 D 4
C 3 D 4
A 1 E 5
B 2 E 5
C 3 E 5
*/
This is a simple example of CROSS JOIN. You can write any of the
following query to get your output.

select * from table1,table2

or

select * from table1 cross join table2

Rgds,
Om


Reply With Quote
  #3  
Old   
newbie
 
Posts: n/a

Default Re: SQL Query - 11-15-2007 , 05:05 AM



thanks a lot

On 15 Nob, 17:22, Om <bubu.prak... (AT) gmail (DOT) com> wrote:
Quote:
On Nov 15, 10:14 am, may_sapak1... (AT) yahoo (DOT) com wrote:



hi everyone. i'm new to sql server.

i have 2 tables. i want to return \all rows in both tables for each
row in table2. please refer to the following. sorry can't get my
thoughts across clearly.

thanks in advance

create table table1 (
c1 char(1),
c2 tinyint
)

insert into table1 values ( 'A', 1 )
insert into table1 values ( 'B', 2 )
insert into table1 values ( 'C', 3 )

create table table2 (
c1 char(1),
c2 tinyint
)

insert into table2 values ( 'D', 4 )
insert into table2 values ( 'E', 5 )

--return table1.*, table2.* from table1 for each row in table2

/*
table1 tabl1 table2 table2
c1 c2 c1 c2
A 1 D 4
B 2 D 4
C 3 D 4
A 1 E 5
B 2 E 5
C 3 E 5
*/

This is a simple example of CROSS JOIN. You can write any of the
following query to get your output.

select * from table1,table2

or

select * from table1 cross join table2

Rgds,
Om


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.