Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine two tables with no relationship between them

I have two table with single column. i.e Type and URL these are as

items
-----
image
image
image
video

items
-----
http://photo.com/some.jpg
http://photo.com/some1.jpg
http://photo.com/some2.jpg
http://video.com/some.avi

I want result as

    Type                     URL
    -----------------------------
    image                    http://photo.com/some.jpg
    image                    http://photo.com/some1.jpg
    image                    http://photo.com/some2.jpg
    video                    http://video.com/some.avi

how can i get result here type and url table have no primery key column

like image 379
manoj Avatar asked Oct 21 '22 08:10

manoj


1 Answers

You can Find you solution Here

Below is the Detail

CREATE TABLE T1 (
    items VARCHAR(10)
)
CREATE TABLE T2 (
    items VARCHAR(100)
)
INSERT INTO T1
VALUES ('image'),('image'),('image'),('video')

INSERT INTO T2
VALUES ('http://photo.com/some.jpg'),('http://photo.com/some1.jpg'),('http://photo.com/some2.jpg'),('http://video.com/some.avi')


select TT1.t1_items as Type,TT2.t2_items as URL from 
(select items t1_items,row_number() over(order by (SELECT 0)) as t1r from t1) as TT1,
(select items t2_items,row_number() over(order by (SELECT 0)) as t2r from t2) as TT2
where TT1.t1r = TT2.t2r
like image 124
Romesh Avatar answered Oct 27 '22 09:10

Romesh