Combine irrelevant columns from two tables in Mysql









up vote
-1
down vote

favorite
1












I just want to compare two results from SELECT Query. so how to combine columns from two tables without any relevance(nothing could be same, so can't use JOIN.. ON.. query).
And here is my Query Code:



SELECT QueryName,Recommendation,Price
FROM PaidGame
WHERE PriceFinal != '0';

SELECT QueryName,Recommendation,Price
FROM FreeGame
WHERE PriceFinal = '0';


My question is, is there any possible way for me to combine these columns in one output.
Here is my output, I want to get these 6 columns together, just for comparison.
enter image description here



enter image description here



And here is what I expected, I just want to make them show together.
enter image description here










share|improve this question























  • more details, I want to see 6 columns for the up question. not just 3
    – Jiacheng Gao
    Nov 9 at 0:16










  • Please provide a short example of input and expected output.
    – Henning Koehler
    Nov 9 at 0:17










  • Learn how to ask question here. stackoverflow.com/help/how-to-ask
    – Eric
    Nov 9 at 0:18










  • sorry about the fewer details about output, and expected output, I just add the screenshot for the output
    – Jiacheng Gao
    Nov 9 at 1:13










  • Your question says there are no similar columns, yet the output image shows that QueryName is the same. Why not join on that?
    – Sam M
    Nov 9 at 2:38














up vote
-1
down vote

favorite
1












I just want to compare two results from SELECT Query. so how to combine columns from two tables without any relevance(nothing could be same, so can't use JOIN.. ON.. query).
And here is my Query Code:



SELECT QueryName,Recommendation,Price
FROM PaidGame
WHERE PriceFinal != '0';

SELECT QueryName,Recommendation,Price
FROM FreeGame
WHERE PriceFinal = '0';


My question is, is there any possible way for me to combine these columns in one output.
Here is my output, I want to get these 6 columns together, just for comparison.
enter image description here



enter image description here



And here is what I expected, I just want to make them show together.
enter image description here










share|improve this question























  • more details, I want to see 6 columns for the up question. not just 3
    – Jiacheng Gao
    Nov 9 at 0:16










  • Please provide a short example of input and expected output.
    – Henning Koehler
    Nov 9 at 0:17










  • Learn how to ask question here. stackoverflow.com/help/how-to-ask
    – Eric
    Nov 9 at 0:18










  • sorry about the fewer details about output, and expected output, I just add the screenshot for the output
    – Jiacheng Gao
    Nov 9 at 1:13










  • Your question says there are no similar columns, yet the output image shows that QueryName is the same. Why not join on that?
    – Sam M
    Nov 9 at 2:38












up vote
-1
down vote

favorite
1









up vote
-1
down vote

favorite
1






1





I just want to compare two results from SELECT Query. so how to combine columns from two tables without any relevance(nothing could be same, so can't use JOIN.. ON.. query).
And here is my Query Code:



SELECT QueryName,Recommendation,Price
FROM PaidGame
WHERE PriceFinal != '0';

SELECT QueryName,Recommendation,Price
FROM FreeGame
WHERE PriceFinal = '0';


My question is, is there any possible way for me to combine these columns in one output.
Here is my output, I want to get these 6 columns together, just for comparison.
enter image description here



enter image description here



And here is what I expected, I just want to make them show together.
enter image description here










share|improve this question















I just want to compare two results from SELECT Query. so how to combine columns from two tables without any relevance(nothing could be same, so can't use JOIN.. ON.. query).
And here is my Query Code:



SELECT QueryName,Recommendation,Price
FROM PaidGame
WHERE PriceFinal != '0';

SELECT QueryName,Recommendation,Price
FROM FreeGame
WHERE PriceFinal = '0';


My question is, is there any possible way for me to combine these columns in one output.
Here is my output, I want to get these 6 columns together, just for comparison.
enter image description here



enter image description here



And here is what I expected, I just want to make them show together.
enter image description here







mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 2:12

























asked Nov 9 at 0:14









Jiacheng Gao

33




33











  • more details, I want to see 6 columns for the up question. not just 3
    – Jiacheng Gao
    Nov 9 at 0:16










  • Please provide a short example of input and expected output.
    – Henning Koehler
    Nov 9 at 0:17










  • Learn how to ask question here. stackoverflow.com/help/how-to-ask
    – Eric
    Nov 9 at 0:18










  • sorry about the fewer details about output, and expected output, I just add the screenshot for the output
    – Jiacheng Gao
    Nov 9 at 1:13










  • Your question says there are no similar columns, yet the output image shows that QueryName is the same. Why not join on that?
    – Sam M
    Nov 9 at 2:38
















  • more details, I want to see 6 columns for the up question. not just 3
    – Jiacheng Gao
    Nov 9 at 0:16










  • Please provide a short example of input and expected output.
    – Henning Koehler
    Nov 9 at 0:17










  • Learn how to ask question here. stackoverflow.com/help/how-to-ask
    – Eric
    Nov 9 at 0:18










  • sorry about the fewer details about output, and expected output, I just add the screenshot for the output
    – Jiacheng Gao
    Nov 9 at 1:13










  • Your question says there are no similar columns, yet the output image shows that QueryName is the same. Why not join on that?
    – Sam M
    Nov 9 at 2:38















more details, I want to see 6 columns for the up question. not just 3
– Jiacheng Gao
Nov 9 at 0:16




more details, I want to see 6 columns for the up question. not just 3
– Jiacheng Gao
Nov 9 at 0:16












Please provide a short example of input and expected output.
– Henning Koehler
Nov 9 at 0:17




Please provide a short example of input and expected output.
– Henning Koehler
Nov 9 at 0:17












Learn how to ask question here. stackoverflow.com/help/how-to-ask
– Eric
Nov 9 at 0:18




Learn how to ask question here. stackoverflow.com/help/how-to-ask
– Eric
Nov 9 at 0:18












sorry about the fewer details about output, and expected output, I just add the screenshot for the output
– Jiacheng Gao
Nov 9 at 1:13




sorry about the fewer details about output, and expected output, I just add the screenshot for the output
– Jiacheng Gao
Nov 9 at 1:13












Your question says there are no similar columns, yet the output image shows that QueryName is the same. Why not join on that?
– Sam M
Nov 9 at 2:38




Your question says there are no similar columns, yet the output image shows that QueryName is the same. Why not join on that?
– Sam M
Nov 9 at 2:38












3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










SELECT QueryName,Recommendation,Price FROM PaidGame WHERE PriceFinal != '0'
UNION ALL
SELECT QueryName,Recommendation,Price FROM FreeGame WHERE PriceFinal = '0';


This is what you are after. The keyword ALL may not be necessary.



More examples: https://www.w3schools.com/sql/sql_union.asp



Updated



SELECT P.QueryName, P.Recommendation, P.Price, F.QueryName, F.Recommendation, F.Price
FROM PaidGame P, FreeGame F


Or



SELECT P.QueryName, P.Recommendation, P.Price, F.QueryName, F.Recommendation, F.Price
FROM PaidGame P
JOIN FreeGame F





share|improve this answer






















  • yes, you are right, but I don't want to combine these 6 columns to 3, I just want to see 6 columns, just like columns: QueryName, Recommendation, Price, QueryName, Recommendation, Price
    – Jiacheng Gao
    Nov 9 at 2:08










  • Check the updated. This will show all combinations so u will have repetitions coz they don't have anything in common. Also is the where conditions needed. Free games are always 0 and Paid games are never 0. Right?
    – Mohammad C
    Nov 9 at 9:50










  • Your edited answer wont work. It is a poor Cross JOIN and will give out 36 rows, if there are 6 rows only in both the tables. Also, Please don't use Old comma based Implicit joins and use Modern Explicit Join based syntax
    – Madhur Bhaiya
    Nov 9 at 9:54






  • 1




    what you updated works for me, thanks a lot, sorry for the late reply
    – Jiacheng Gao
    Nov 12 at 17:05

















up vote
0
down vote













You could do a union or union all to combine the two selects or compare the checksum of the 3 columns to see if they are equal






share|improve this answer




















  • thanks, I understand, but I just want to make them show together, I changed my question, you could see what I expected, 6 columns.
    – Jiacheng Gao
    Nov 9 at 2:14










  • You could do row_number() on each table into temp tables then join or outer join the two tables based on the row number
    – Jassem Abdal
    Nov 10 at 13:10

















up vote
0
down vote













Aside from the issue that this would be better done in the presentation layer (e.g. XSL, report etc), you can do it.



My solution would be to create an index table, then join to each of the table querie,s adding in a row identifier. Something like this (hopefully this translates to Mysql - I'm more of a TSQL person):



create table #index (indexnum int)

declare @minnum as int set @minnum=1 while @minnum<1000 BEGIN

insert into #index select @minnum set @minnum=@minnum+1 END


create table #paidgame (queryname varchar(100), recommendation varchar(100), price varchar (100))

create table #freegame (queryname varchar(100), recommendation varchar(100), price varchar (100))

insert into #paidgame select 'Game 1', 'Good', '£4.99' UNION ALL select 'Game 2', 'Good', '£3.99' UNION ALL select 'Game 3', 'Good', '£5.99'

insert into #freegame select 'Game 4', 'Good', '£0.00' UNION ALL select 'Game 5', 'Good', '£0.00' UNION ALL select 'Game 6', 'Good', '£0.00'


select * from

#index i left join (select * from (

SELECT QueryName,Recommendation,Price, dense_rank() OVER (ORDER BY queryname) as prank FROM #PaidGame pg ) aa ) t1 on t1.prank=i.indexnumn

left join

(select * from (SELECT QueryName,Recommendation,Price, dense_rank() OVER (ORDER BY queryname) as frank FROM #FreeGame fg ) bb) t2 on i.indexnumn=t2.frank

where t1.queryname is not null and t2.queryname is not null





share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53218049%2fcombine-irrelevant-columns-from-two-tables-in-mysql%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    SELECT QueryName,Recommendation,Price FROM PaidGame WHERE PriceFinal != '0'
    UNION ALL
    SELECT QueryName,Recommendation,Price FROM FreeGame WHERE PriceFinal = '0';


    This is what you are after. The keyword ALL may not be necessary.



    More examples: https://www.w3schools.com/sql/sql_union.asp



    Updated



    SELECT P.QueryName, P.Recommendation, P.Price, F.QueryName, F.Recommendation, F.Price
    FROM PaidGame P, FreeGame F


    Or



    SELECT P.QueryName, P.Recommendation, P.Price, F.QueryName, F.Recommendation, F.Price
    FROM PaidGame P
    JOIN FreeGame F





    share|improve this answer






















    • yes, you are right, but I don't want to combine these 6 columns to 3, I just want to see 6 columns, just like columns: QueryName, Recommendation, Price, QueryName, Recommendation, Price
      – Jiacheng Gao
      Nov 9 at 2:08










    • Check the updated. This will show all combinations so u will have repetitions coz they don't have anything in common. Also is the where conditions needed. Free games are always 0 and Paid games are never 0. Right?
      – Mohammad C
      Nov 9 at 9:50










    • Your edited answer wont work. It is a poor Cross JOIN and will give out 36 rows, if there are 6 rows only in both the tables. Also, Please don't use Old comma based Implicit joins and use Modern Explicit Join based syntax
      – Madhur Bhaiya
      Nov 9 at 9:54






    • 1




      what you updated works for me, thanks a lot, sorry for the late reply
      – Jiacheng Gao
      Nov 12 at 17:05














    up vote
    0
    down vote



    accepted










    SELECT QueryName,Recommendation,Price FROM PaidGame WHERE PriceFinal != '0'
    UNION ALL
    SELECT QueryName,Recommendation,Price FROM FreeGame WHERE PriceFinal = '0';


    This is what you are after. The keyword ALL may not be necessary.



    More examples: https://www.w3schools.com/sql/sql_union.asp



    Updated



    SELECT P.QueryName, P.Recommendation, P.Price, F.QueryName, F.Recommendation, F.Price
    FROM PaidGame P, FreeGame F


    Or



    SELECT P.QueryName, P.Recommendation, P.Price, F.QueryName, F.Recommendation, F.Price
    FROM PaidGame P
    JOIN FreeGame F





    share|improve this answer






















    • yes, you are right, but I don't want to combine these 6 columns to 3, I just want to see 6 columns, just like columns: QueryName, Recommendation, Price, QueryName, Recommendation, Price
      – Jiacheng Gao
      Nov 9 at 2:08










    • Check the updated. This will show all combinations so u will have repetitions coz they don't have anything in common. Also is the where conditions needed. Free games are always 0 and Paid games are never 0. Right?
      – Mohammad C
      Nov 9 at 9:50










    • Your edited answer wont work. It is a poor Cross JOIN and will give out 36 rows, if there are 6 rows only in both the tables. Also, Please don't use Old comma based Implicit joins and use Modern Explicit Join based syntax
      – Madhur Bhaiya
      Nov 9 at 9:54






    • 1




      what you updated works for me, thanks a lot, sorry for the late reply
      – Jiacheng Gao
      Nov 12 at 17:05












    up vote
    0
    down vote



    accepted







    up vote
    0
    down vote



    accepted






    SELECT QueryName,Recommendation,Price FROM PaidGame WHERE PriceFinal != '0'
    UNION ALL
    SELECT QueryName,Recommendation,Price FROM FreeGame WHERE PriceFinal = '0';


    This is what you are after. The keyword ALL may not be necessary.



    More examples: https://www.w3schools.com/sql/sql_union.asp



    Updated



    SELECT P.QueryName, P.Recommendation, P.Price, F.QueryName, F.Recommendation, F.Price
    FROM PaidGame P, FreeGame F


    Or



    SELECT P.QueryName, P.Recommendation, P.Price, F.QueryName, F.Recommendation, F.Price
    FROM PaidGame P
    JOIN FreeGame F





    share|improve this answer














    SELECT QueryName,Recommendation,Price FROM PaidGame WHERE PriceFinal != '0'
    UNION ALL
    SELECT QueryName,Recommendation,Price FROM FreeGame WHERE PriceFinal = '0';


    This is what you are after. The keyword ALL may not be necessary.



    More examples: https://www.w3schools.com/sql/sql_union.asp



    Updated



    SELECT P.QueryName, P.Recommendation, P.Price, F.QueryName, F.Recommendation, F.Price
    FROM PaidGame P, FreeGame F


    Or



    SELECT P.QueryName, P.Recommendation, P.Price, F.QueryName, F.Recommendation, F.Price
    FROM PaidGame P
    JOIN FreeGame F






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 9 at 14:29

























    answered Nov 9 at 1:35









    Mohammad C

    1,1281212




    1,1281212











    • yes, you are right, but I don't want to combine these 6 columns to 3, I just want to see 6 columns, just like columns: QueryName, Recommendation, Price, QueryName, Recommendation, Price
      – Jiacheng Gao
      Nov 9 at 2:08










    • Check the updated. This will show all combinations so u will have repetitions coz they don't have anything in common. Also is the where conditions needed. Free games are always 0 and Paid games are never 0. Right?
      – Mohammad C
      Nov 9 at 9:50










    • Your edited answer wont work. It is a poor Cross JOIN and will give out 36 rows, if there are 6 rows only in both the tables. Also, Please don't use Old comma based Implicit joins and use Modern Explicit Join based syntax
      – Madhur Bhaiya
      Nov 9 at 9:54






    • 1




      what you updated works for me, thanks a lot, sorry for the late reply
      – Jiacheng Gao
      Nov 12 at 17:05
















    • yes, you are right, but I don't want to combine these 6 columns to 3, I just want to see 6 columns, just like columns: QueryName, Recommendation, Price, QueryName, Recommendation, Price
      – Jiacheng Gao
      Nov 9 at 2:08










    • Check the updated. This will show all combinations so u will have repetitions coz they don't have anything in common. Also is the where conditions needed. Free games are always 0 and Paid games are never 0. Right?
      – Mohammad C
      Nov 9 at 9:50










    • Your edited answer wont work. It is a poor Cross JOIN and will give out 36 rows, if there are 6 rows only in both the tables. Also, Please don't use Old comma based Implicit joins and use Modern Explicit Join based syntax
      – Madhur Bhaiya
      Nov 9 at 9:54






    • 1




      what you updated works for me, thanks a lot, sorry for the late reply
      – Jiacheng Gao
      Nov 12 at 17:05















    yes, you are right, but I don't want to combine these 6 columns to 3, I just want to see 6 columns, just like columns: QueryName, Recommendation, Price, QueryName, Recommendation, Price
    – Jiacheng Gao
    Nov 9 at 2:08




    yes, you are right, but I don't want to combine these 6 columns to 3, I just want to see 6 columns, just like columns: QueryName, Recommendation, Price, QueryName, Recommendation, Price
    – Jiacheng Gao
    Nov 9 at 2:08












    Check the updated. This will show all combinations so u will have repetitions coz they don't have anything in common. Also is the where conditions needed. Free games are always 0 and Paid games are never 0. Right?
    – Mohammad C
    Nov 9 at 9:50




    Check the updated. This will show all combinations so u will have repetitions coz they don't have anything in common. Also is the where conditions needed. Free games are always 0 and Paid games are never 0. Right?
    – Mohammad C
    Nov 9 at 9:50












    Your edited answer wont work. It is a poor Cross JOIN and will give out 36 rows, if there are 6 rows only in both the tables. Also, Please don't use Old comma based Implicit joins and use Modern Explicit Join based syntax
    – Madhur Bhaiya
    Nov 9 at 9:54




    Your edited answer wont work. It is a poor Cross JOIN and will give out 36 rows, if there are 6 rows only in both the tables. Also, Please don't use Old comma based Implicit joins and use Modern Explicit Join based syntax
    – Madhur Bhaiya
    Nov 9 at 9:54




    1




    1




    what you updated works for me, thanks a lot, sorry for the late reply
    – Jiacheng Gao
    Nov 12 at 17:05




    what you updated works for me, thanks a lot, sorry for the late reply
    – Jiacheng Gao
    Nov 12 at 17:05












    up vote
    0
    down vote













    You could do a union or union all to combine the two selects or compare the checksum of the 3 columns to see if they are equal






    share|improve this answer




















    • thanks, I understand, but I just want to make them show together, I changed my question, you could see what I expected, 6 columns.
      – Jiacheng Gao
      Nov 9 at 2:14










    • You could do row_number() on each table into temp tables then join or outer join the two tables based on the row number
      – Jassem Abdal
      Nov 10 at 13:10














    up vote
    0
    down vote













    You could do a union or union all to combine the two selects or compare the checksum of the 3 columns to see if they are equal






    share|improve this answer




















    • thanks, I understand, but I just want to make them show together, I changed my question, you could see what I expected, 6 columns.
      – Jiacheng Gao
      Nov 9 at 2:14










    • You could do row_number() on each table into temp tables then join or outer join the two tables based on the row number
      – Jassem Abdal
      Nov 10 at 13:10












    up vote
    0
    down vote










    up vote
    0
    down vote









    You could do a union or union all to combine the two selects or compare the checksum of the 3 columns to see if they are equal






    share|improve this answer












    You could do a union or union all to combine the two selects or compare the checksum of the 3 columns to see if they are equal







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 9 at 1:28









    Jassem Abdal

    1




    1











    • thanks, I understand, but I just want to make them show together, I changed my question, you could see what I expected, 6 columns.
      – Jiacheng Gao
      Nov 9 at 2:14










    • You could do row_number() on each table into temp tables then join or outer join the two tables based on the row number
      – Jassem Abdal
      Nov 10 at 13:10
















    • thanks, I understand, but I just want to make them show together, I changed my question, you could see what I expected, 6 columns.
      – Jiacheng Gao
      Nov 9 at 2:14










    • You could do row_number() on each table into temp tables then join or outer join the two tables based on the row number
      – Jassem Abdal
      Nov 10 at 13:10















    thanks, I understand, but I just want to make them show together, I changed my question, you could see what I expected, 6 columns.
    – Jiacheng Gao
    Nov 9 at 2:14




    thanks, I understand, but I just want to make them show together, I changed my question, you could see what I expected, 6 columns.
    – Jiacheng Gao
    Nov 9 at 2:14












    You could do row_number() on each table into temp tables then join or outer join the two tables based on the row number
    – Jassem Abdal
    Nov 10 at 13:10




    You could do row_number() on each table into temp tables then join or outer join the two tables based on the row number
    – Jassem Abdal
    Nov 10 at 13:10










    up vote
    0
    down vote













    Aside from the issue that this would be better done in the presentation layer (e.g. XSL, report etc), you can do it.



    My solution would be to create an index table, then join to each of the table querie,s adding in a row identifier. Something like this (hopefully this translates to Mysql - I'm more of a TSQL person):



    create table #index (indexnum int)

    declare @minnum as int set @minnum=1 while @minnum<1000 BEGIN

    insert into #index select @minnum set @minnum=@minnum+1 END


    create table #paidgame (queryname varchar(100), recommendation varchar(100), price varchar (100))

    create table #freegame (queryname varchar(100), recommendation varchar(100), price varchar (100))

    insert into #paidgame select 'Game 1', 'Good', '£4.99' UNION ALL select 'Game 2', 'Good', '£3.99' UNION ALL select 'Game 3', 'Good', '£5.99'

    insert into #freegame select 'Game 4', 'Good', '£0.00' UNION ALL select 'Game 5', 'Good', '£0.00' UNION ALL select 'Game 6', 'Good', '£0.00'


    select * from

    #index i left join (select * from (

    SELECT QueryName,Recommendation,Price, dense_rank() OVER (ORDER BY queryname) as prank FROM #PaidGame pg ) aa ) t1 on t1.prank=i.indexnumn

    left join

    (select * from (SELECT QueryName,Recommendation,Price, dense_rank() OVER (ORDER BY queryname) as frank FROM #FreeGame fg ) bb) t2 on i.indexnumn=t2.frank

    where t1.queryname is not null and t2.queryname is not null





    share|improve this answer
























      up vote
      0
      down vote













      Aside from the issue that this would be better done in the presentation layer (e.g. XSL, report etc), you can do it.



      My solution would be to create an index table, then join to each of the table querie,s adding in a row identifier. Something like this (hopefully this translates to Mysql - I'm more of a TSQL person):



      create table #index (indexnum int)

      declare @minnum as int set @minnum=1 while @minnum<1000 BEGIN

      insert into #index select @minnum set @minnum=@minnum+1 END


      create table #paidgame (queryname varchar(100), recommendation varchar(100), price varchar (100))

      create table #freegame (queryname varchar(100), recommendation varchar(100), price varchar (100))

      insert into #paidgame select 'Game 1', 'Good', '£4.99' UNION ALL select 'Game 2', 'Good', '£3.99' UNION ALL select 'Game 3', 'Good', '£5.99'

      insert into #freegame select 'Game 4', 'Good', '£0.00' UNION ALL select 'Game 5', 'Good', '£0.00' UNION ALL select 'Game 6', 'Good', '£0.00'


      select * from

      #index i left join (select * from (

      SELECT QueryName,Recommendation,Price, dense_rank() OVER (ORDER BY queryname) as prank FROM #PaidGame pg ) aa ) t1 on t1.prank=i.indexnumn

      left join

      (select * from (SELECT QueryName,Recommendation,Price, dense_rank() OVER (ORDER BY queryname) as frank FROM #FreeGame fg ) bb) t2 on i.indexnumn=t2.frank

      where t1.queryname is not null and t2.queryname is not null





      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Aside from the issue that this would be better done in the presentation layer (e.g. XSL, report etc), you can do it.



        My solution would be to create an index table, then join to each of the table querie,s adding in a row identifier. Something like this (hopefully this translates to Mysql - I'm more of a TSQL person):



        create table #index (indexnum int)

        declare @minnum as int set @minnum=1 while @minnum<1000 BEGIN

        insert into #index select @minnum set @minnum=@minnum+1 END


        create table #paidgame (queryname varchar(100), recommendation varchar(100), price varchar (100))

        create table #freegame (queryname varchar(100), recommendation varchar(100), price varchar (100))

        insert into #paidgame select 'Game 1', 'Good', '£4.99' UNION ALL select 'Game 2', 'Good', '£3.99' UNION ALL select 'Game 3', 'Good', '£5.99'

        insert into #freegame select 'Game 4', 'Good', '£0.00' UNION ALL select 'Game 5', 'Good', '£0.00' UNION ALL select 'Game 6', 'Good', '£0.00'


        select * from

        #index i left join (select * from (

        SELECT QueryName,Recommendation,Price, dense_rank() OVER (ORDER BY queryname) as prank FROM #PaidGame pg ) aa ) t1 on t1.prank=i.indexnumn

        left join

        (select * from (SELECT QueryName,Recommendation,Price, dense_rank() OVER (ORDER BY queryname) as frank FROM #FreeGame fg ) bb) t2 on i.indexnumn=t2.frank

        where t1.queryname is not null and t2.queryname is not null





        share|improve this answer












        Aside from the issue that this would be better done in the presentation layer (e.g. XSL, report etc), you can do it.



        My solution would be to create an index table, then join to each of the table querie,s adding in a row identifier. Something like this (hopefully this translates to Mysql - I'm more of a TSQL person):



        create table #index (indexnum int)

        declare @minnum as int set @minnum=1 while @minnum<1000 BEGIN

        insert into #index select @minnum set @minnum=@minnum+1 END


        create table #paidgame (queryname varchar(100), recommendation varchar(100), price varchar (100))

        create table #freegame (queryname varchar(100), recommendation varchar(100), price varchar (100))

        insert into #paidgame select 'Game 1', 'Good', '£4.99' UNION ALL select 'Game 2', 'Good', '£3.99' UNION ALL select 'Game 3', 'Good', '£5.99'

        insert into #freegame select 'Game 4', 'Good', '£0.00' UNION ALL select 'Game 5', 'Good', '£0.00' UNION ALL select 'Game 6', 'Good', '£0.00'


        select * from

        #index i left join (select * from (

        SELECT QueryName,Recommendation,Price, dense_rank() OVER (ORDER BY queryname) as prank FROM #PaidGame pg ) aa ) t1 on t1.prank=i.indexnumn

        left join

        (select * from (SELECT QueryName,Recommendation,Price, dense_rank() OVER (ORDER BY queryname) as frank FROM #FreeGame fg ) bb) t2 on i.indexnumn=t2.frank

        where t1.queryname is not null and t2.queryname is not null






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 14:06









        iainc

        336




        336



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53218049%2fcombine-irrelevant-columns-from-two-tables-in-mysql%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            How do I collapse sections of code in Visual Studio Code for Windows?

            Node.js puppeteer - Use values from array in a loop to cycle through pages