简体   繁体   中英

How to inner join two or more tables together in a query?

The query i want to the results should get updated in my customer_info table. I do know have any relation ships between the table, however i have to use inner join to run queries. Please help.

current tags table

_reader_ID_|__tag_no__|__area |_maxtime_____
           |          |       |

Tag_logs table

reader_ID_|__tag_no__|timestamp___
          |          |       

Aisle_info table

reader_ID_|_area_|
          |      |      

customer_info table

name_|__email__|__reader_id |_tag_no|_area|_maxtime_
     |         |            |       |     |
INSERT INTO customer_info
SELECT aisle_info.reader_ID, tag_no, aisle_info.area, customer_info.name, TIMESTAMPDIFF(SECOND,MIN(timestamp),MAX(timestamp)) AS MAXTIME FROM tag_logs INNER JOIN aisle_info ON tag_logs.reader_ID = aisle_info.reader_ID AND customer_info INNER JOIN current_tags ON customer_info.name = customer_info.name 
WHERE tag_no = 3222813112261

1052 - Column 'tag_no' in field list is ambiguous

You should add the table name when a column is present in more then a table so assuming that tag_no is present in tag_logs table try tag_logs.tag_no

INSERT INTO customer_info
SELECT aisle_info.reader_ID
    , tag_logs.tag_no
    , aisle_info.area
    , customer_info.name
    , TIMESTAMPDIFF(SECOND,MIN(timestamp)
    ,MAX(timestamp)) AS MAXTIME 
FROM tag_logs 
INNER JOIN aisle_info ON tag_logs.reader_ID = aisle_info.reader_ID 
    AND customer_info 
INNER JOIN current_tags ON customer_info.name = customer_info.name 
WHERE tag_logs.tag_no = 3222813112261

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