简体   繁体   English

如何使用MySql从数据库中的两个表中获取数据

[英]How to get data from two tables from database with MySql

What I want to do is to get all of the information from one table where the username and the number is the same as in the table, and then on the same call I want to join two rows from a different table with the same title as the first table row named "title" (hopefully I got it clear enough). 我想要做的是从一个表中获取用户名和数字与表中相同的所有信息,然后在同一个调用中,我想从另一个表中加入两行,标题与第一个名为“title”的表格行(希望我说得够清楚)。

Tried this: 试过这个:

`SELECT * FROM movies_in_theater 
     WHERE username = "${req.username}" 
     AND theater_number = '${req.theater}'
     LEFT JOIN movie_info.key_exp, movie_info.key_exp_time 
     WHERE movies_in_theater.movie_title = movie_info.title
     `

Like this: 像这样:

SELECT t.username
     , t.theater_number
     , t.movie_title
     , i.key_exp
     , i.key_exp_time

  FROM movies_in_theater t

  LEFT
  JOIN movie_info i
    ON i.title = t.movie_title

 WHERE t.username       = ?
   AND t.theater_number = ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM