Satinderdeep Satinderdeep - 1 month ago 17
MySQL Question

Select all results from table1 as well table2 in mysql where both table has one common id

I have 2 tables.

table1 structure

id | status_type | status_content |
1 | image | abc |
2 | text | def |
3 | video | ghi |


table2 stucture

|file_id | status_id | file_name |
| 1 | 1 | image.png |
| 2 | 3 | video.mp4 |


and I want all results from both tables. e.g.

id | status_type | status_content | file_id | file_name |
1 | image | abc | 1 | image.png |
2 | text | def | blank | blank |
3 | video | ghi | 3 | video.mp4 |

Answer

You can use:

SELECT table1.id,table1.status_type, table1.status_content,
     table2.status_id,table2.file_name,
     FROM table2
     INNER JOIN table2
     ON table1.id=table2.file_id ;

A join can help you.

Comments