Страницы

Поиск по вопросам

вторник, 5 марта 2019 г.

сложный запрос в базу mysql [дубликат]

На данный вопрос уже ответили: Как соединить две таблицы БД 1 ответ здравствуйте, есть две таблицы:
`oc_vendor` ( `vendor_id` int(11) NOT NULL AUTO_INCREMENT, `vproduct_id` int(11) NOT NULL, `ori_country` varchar(128) COLLATE utf8_bin NOT NULL, `product_cost` decimal(15,4) NOT NULL DEFAULT '0.0000', `shipping_method` int(2) NOT NULL DEFAULT '0', `prefered_shipping` int(2) NOT NULL DEFAULT '0', `shipping_cost` decimal(15,4) NOT NULL DEFAULT '0.0000', `vtotal` decimal(15,4) NOT NULL DEFAULT '0.0000', `product_url` text COLLATE utf8_bin NOT NULL, `vendor` int(11) NOT NULL, `wholesale` varchar(128) COLLATE utf8_bin NOT NULL, `date_add` datetime NOT NULL,
и вторая:
`oc_vendors` ( `vendor_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `vendor_name` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `commission_id` int(11) NOT NULL, `product_limit_id` int(11) NOT NULL, `company` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `company_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `vendor_description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `telephone` varchar(20) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `fax` varchar(20) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `email` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `paypal_email` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `iban` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `bank_name` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `bank_address` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `swift_bic` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `tax_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `accept_paypal` tinyint(2) NOT NULL, `accept_cheques` tinyint(2) NOT NULL, `accept_bank_transfer` tinyint(2) NOT NULL, `store_url` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `vendor_image` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `firstname` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `lastname` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `address_1` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `address_2` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `city` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `postcode` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `country_id` int(11) NOT NULL, `zone_id` int(11) NOT NULL, `sort_order` int(11) NOT NULL, `date_add` datetime NOT NULL,
можно ли одним сложным запросом сделать выборку из этих двух, если можно то как??? а выбрать нужно vendor_name, vendor_description, vendor_image, firstname, lastname from oc_vendors where vproduct_id = '.$product_id где $product_id - id продукта в таблице oc_vendor ???


Ответ

На самом деле все оказалось проще чем я думал. Запрос выглядит так:
Select vendor_name, firstname, lastname, ... From vendors, vendor where vendors.vendor_id=vendor.vendor and vendor.vproduct_id=product_id
Всем спасибо )

Комментариев нет:

Отправить комментарий