John Davidson

php - Show all available videos JOINED two tables

0 comments
Message:


I have two tables news and video. Need to show all available videos per new_id


Table news























id title services
1 new_title Video
2 new_title_2 Video


My Answer:
You can achieve this by using a SQL query with a JOIN statement to combine the two tables and retrieve the desired information. Here is an example query that shows all available videos per new_id in the news table:

sql
SELECT n.id, n.title, v.video_title
FROM news n
LEFT JOIN video v ON n.id = v.new_id
ORDER BY n.id;


In this query:
- We select the id and title columns from the news table and the video_title column from the video table.
- We use a LEFT JOIN to combine the two tables based on the new_id column.
- The ORDER BY clause is used to sort the results by the news id.

This query will return a list of all news items along with the available videos for each news item.

Rate this post

3 of 5 based on 3587 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us