Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two Table A and B.both table having different data,i want to select table column with table B all colmns for each row of the tabl A.is it possible?
Table A    Table B
-------    ------
d1         1 
d2         2
d3         3
d4         4 
d5         5
d6         6
d7         7         
d8         8
d9         9
d10        10
d11        11
d12        12
d13        13  
d14        14
d15        15
d16        16
d17        17


result table like this i need
Table C
col1   col2
d1     1
d1     2
d1     3
d1     4
d1     5
d1     6
d1     7
d1     8
d1     9
d1     10
d1     11
d1     12
d1     13
d1     14
d1     15
d1     16
d1     17
d2     1
d2     2
d2     3
d2     4
d2     5
d2     6
..
..
..


like this it should come,it is just example original data will have more that 1000 rows/I want to do in one shot

What I have tried:

Code>>Plain text for formatting text represents table values
Posted
Updated 16-Sep-19 23:32pm
v3

SELECT col1,col2 FROM A cross join B

Use this.. its may be help you
 
Share this answer
 
Comments
Maciej Los 12-Sep-19 6:38am    
You're wrong. A Cross join returns cartesian product. Each row in the first table is mixed/joined with each row in the second table.
[EDIT]
Sorry, i misunderstand the question.
Good answer.
Simple,
SQL
SELECT col1,col2
FROM A,B


For example:
SQL
SELECT * FROM
(SELECT 'd1' as col1
UNION
SELECT 'd2') AS T1,
(SELECT 1 as col2
UNION
SELECT 2) AS T2
ORDER BY col1

Result:
col1	col2
d1	    1
d1	    2
d2	    1
d2	    2


Hope, it helps :)
 
Share this answer
 
v2
Comments
Member 11337367 19-Feb-15 0:50am    
see i have more than 1000 rows in each column how can i write select statment for 1000 times
SELECT col1,col2 FROM A CROSS APPLY B
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900