使用从另一张表中获得的值从一个表中选择行 [英] Selecting rows from one table using values gotten from another table MYSQL

查看:44
本文介绍了使用从另一张表中获得的值从一个表中选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在数据库中有2个mysql表

I have currently have 2 mysql tables in my db

FilmFilm_Ratings_Report

胶片的主键是filmid,用于标识Film_Ratings_Report表中的胶片等级.

The primary key for Film is filmid which is used to identify the film ratings in the Film_Ratings_Report table.

我想知道是否有可能仅使用MYSQL查询来搜索收视率表并收集符合特定条件的所有电影ID,然后使用选定的ID从电影表中获取电影标题.下面是使用不起作用的MYSQL查询:

I would like to know if its possible using a MYSQL query only to search the ratings table and collect all film ids which fit a certain criteria then use the selected IDs to get the film titles from the Film table. Below is the MYSQL query Im using which isnt working:

SELECT * 
FROM film 
UNION SELECT filmid 
      FROM film_rating_report 
      WHERE rating = 'GE' 
      LIMIT 0,0

我对MYSQL比较满意,希望对此有所帮助.

I am relatively green to MYSQL and would appreciate any help on this.

预先感谢

推荐答案

SELECT * FROM film WHERE id IN 
  (SELECT filmid FROM film_rating_report WHERE rating = 'GE');

应该工作

这篇关于使用从另一张表中获得的值从一个表中选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆