J
J
Jedi2017-09-09 19:22:11
MySQL
Jedi, 2017-09-09 19:22:11

How to select only those records that are written in another table?

Hello, here are my tables:
1) projects - A table that stores projects
id
title
src_id
created_at
2) images - and here all project images are stored.
id
project_id
src
size
How to select from the table -- only those records from `images` that were recorded in the `projects` table (src_id serves as an identifier for selection) ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-09-10
@PHPjedi

src_id serves as an identifier for the fetch

maybe you meant project_id?
SELECT images.*
FROM images INNER JOIN projects
ON images.project_id = projects.id
WHERE projects.id IS NOT NULL

this query will return all fields from the images table
whose project_id refers to an existing entry in projects

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question