This question has already been answered:

Hello, there are two tables:

`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, 

and second:

 `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, 

Is it possible to make a sample of these two in one complex query, if so how can it be ??? you need to choose vendor_name, vendor_description, vendor_image, firstname, lastname from oc_vendors where vproduct_id = '. $ product_id where $ product_id is the product id in the table oc_vendor ???

Reported as a duplicate by Mike , Kromster , Denis , aleksandr barakin , Bald Aug 26 '16 at 7:38 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • jojo mono left join for example - Naumov
  • one
    This can only be done with a simple query. Because the joining of two tables in a query is a basic level of knowledge of the SQL language. Even tutorials are not necessary to read. Just look at the examples of requests at least on this site in questions. ru.stackoverflow.com/… - Mike
  • How exactly?? If not hard! Thank you - privetsh

2 answers 2

If I understand correctly, then you do not have oc_vendors in the table, there oc_vendors no association field with the oc_vendor table oc_vendor but it must be in order for any query to work for two or more tables. If you had a field in the oc_vendors table (let's call it, for example id_ven_to_venders ), you could create a query like this:

 SELECT vendor_name, vendor_description, vendor_image, firstname, lastname Where id_ven_to_venders ='.$product_id.' 

the field by which the tables are associated should have the same value as the associated record from another table .. I do not really understand the logic of your tables and what is stored in them and how it overlaps, but assuming that 1 other table oc_vendor belongs to several other oc_vendor ( ) from the oc_vendors table oc_vendors our oc_vendors field would have to contain the vendor_id values ​​from the oc_vendor table (respectively, setting the 1 to 1 or 1 to many association)

ZY The semantics of the tables is terrible, I can be mistaken but understand by the name of the fields and tables that they contain extremely difficult, I recommend calling the tables, fields and variables as accessible as possible and different from others, otherwise it is easy for you and the developers who will support your code

    In fact, everything was easier than I thought. The request looks like this:

     Select vendor_name, firstname, lastname, ... From vendors, vendor where vendors.vendor_id=vendor.vendor and vendor.vproduct_id=product_id 

    Thanks to all )