Mysql 当另一个表有许多行对应于母表中的一行时,如何执行表联接
我有两个表格-->Mysql 当另一个表有许多行对应于母表中的一行时,如何执行表联接,mysql,Mysql,我有两个表格-->tbl\u书籍详细信息和tbl\u表格追踪 tbl_book_details has columns bd_book_code, bd_isbn, bd_title, bd_edition, bd_author, bd_publisher, bd_supplier, bd_page, bd_price_type, bd_cost_price, bd_price, bd_Tax, bd_covering, bd_availabi
tbl\u书籍详细信息和tbl\u表格追踪
tbl_book_details has columns bd_book_code,
bd_isbn,
bd_title,
bd_edition,
bd_author,
bd_publisher,
bd_supplier,
bd_page,
bd_price_type,
bd_cost_price,
bd_price,
bd_Tax,
bd_covering,
bd_availability,
bd_keywords,
bd_notes,
bd_details,
bd_news_latter,
bd_etDate,
bd_weight,
bd_expire_date,
bd_status
tbl_table_traking has columns
tt_id,
tt_action,
tt_table,
tt_record_id,
tt_on_date,
tt_user,
tt_status
该过程是在tbl_book_details上定义的触发器,在插入/修改的情况下,在tbl_table_traking中插入数据,以便在何时以及谁修改了记录时进行跟踪
到目前为止,我一直在使用以下不是联接的查询-->
当记录数低于300万时,它工作正常,但现在脚本超时
我已经在“tt\u ondate
”和tt\u action
”上的tbl\u table\u traking
上编制了索引
如果有任何方法可以将其转换为联接或提高性能
表跟踪查询返回记录修改的最短日期
我的数据库在mysql中。您应该能够执行类似的操作
SELECT
tbl_books_details.bd_book_code AS bkid,
tbl_books_details.bd_isbn,
tbl_books_details.bd_title AS title,
tbl_table_traking.tt_on_date
FROM
tbl_books_details
INNER JOIN tbl_table_tracking
tbl_books_details.bd_book_code = tbl_table_tracking.tt_record_id
WHERE tt_action = 'MODIFY';
希望这有帮助…@Ranta…请格式化代码以便更好地理解。看起来您没有包含一半的查询。你能发布完整的查询吗。另外,如果你知道你需要一个连接,为什么不试试呢?@JohnFx我无法将查询更改为连接,因此我在这里询问了一些有关使用连接编写查询的文档:
SELECT
tbl_books_details.bd_book_code AS bkid,
tbl_books_details.bd_isbn,
tbl_books_details.bd_title AS title,
tbl_table_traking.tt_on_date
FROM
tbl_books_details
INNER JOIN tbl_table_tracking
tbl_books_details.bd_book_code = tbl_table_tracking.tt_record_id
WHERE tt_action = 'MODIFY';