简体   繁体   中英

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).

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 = ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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