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

How do I get data from another column when I've already used JOIN

Let’s say I have two tables:

Table 1 has columns:
ID,
Product,
Name

Table 2 has columns:
ProductID,
Start Date,
End Date

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

ID and Product ID are the same, how do I get Start Date and End Date in the first table?

This is the code I’ve used:

SELECT 
        table1.Name, 
        table1.ID, 
        table1.Product 
  FROM table1
  JOIN table 2
  ON table1.ID=table2.ProductID

How can I also get the Start Date and End date from table2 in this query?

>Solution :

You can just add the table names to the list in the SELECT:

SELECT 
      table1.Name, 
      table1.ID, 
      table1.Product,
      table2.StartDate,
      table2.EndDate
FROM 
  table1
  JOIN table2
    ON table1.ID = table2.ProductID
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