Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cartesian multiplication in SQL and update null columns

I have these two tables in MySQL database:

tbl_hashs >

h_id r_id hash
1 122 xx
2 123 xx

tbl_sandbox >

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

h_id r_id hash
NULL NULL xx

finally I want to have this table:

query result should be like >>>

h_id r_id hash
1 122 xx
1 123 xx
2 122 xx
2 123 xx

I think something like "Cartesian multiplication" can help me. but I can’t do it in MySQL.
please somebody help me with proper query.

>Solution :

SELECT
   t1.h_id,
   t2.r_id,
   t2.hash
FROM tbl_hashs t1
CROSS JOIN tbl_hashs t2
ORDER BY t1.h_id

But I did not use tbl_sandbox, is that good ?

https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=32926caddc063c2adcbc03944ce489ce

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading