There are 3 tables:
CREATE TABLE `item` ( `id` bigint(20) UNSIGNED NOT NULL, `user_id` varchar(50) NOT NULL, `code` varchar(14) NOT NULL, `workname` varchar(255) NOT NULL, `markedflag` tinyint(1) NOT NULL DEFAULT '1' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `price` ( `id` bigint(20) UNSIGNED NOT NULL, `item_id` bigint(20) UNSIGNED NOT NULL, `doc_id` bigint(20) UNSIGNED NOT NULL, `price` double NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `doc` ( `id` bigint(20) UNSIGNED NOT NULL, `code` int(8) UNSIGNED NOT NULL, `docdate` datetime NOT NULL, `user_id` varchar(50) NOT NULL, `apply` tinyint(1) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - in item is the output associated with a specific user through user_id;
- in doc there are records (documents) that are also bound to the user via user_id and have the date of creation of docdate;
- in the price is the price itself which is associated with the product through item_id and is associated with the document through doc_id;
Through the creation of a new document, the price of the product is updated, all products and only one position can be updated. From all this you need to get a list of all products for a specific user with the latest prices. The result should be a item.id , price.price , doc.id , doc.docdate
Thanks in advance to everyone who will help :)