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

SQL: Help creating a table based on another tables value

I am new to SQL and am currently doing a project on MSQL 2019.

I have one table with a list of codes mapping a "Loss ID" to a Reason.

enter image description here

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

Now I have another table that just gives you the number of the Loss ID but not the text version of it.
enter image description here

How can I create a table that will take the number code and automatically change it to the text version of it?

Im not even sure what this type of scripting is called, so even pointers on what to google or look for would be very useful.

>Solution :

Rather than creating another table use a view.

Let’s call your tables tbl1 and tbl2. The view would be:

CREATE VIEW my_view AS SELECT tbl2.your_date_column, 
                              tbl2.LossID,
                              tbl1.reason
                       FROM tbl1 
                       INNER JOIN tbl2 on  tbl1.LossID=tbl2.LossID;

Lear more about VIEWS https://www.mysqltutorial.org/create-sql-views-mysql.aspx

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