1

I have 2 tables, one with Vendors and one with Products. There is a foreign key shared between the 2 tables which is a Code. I need a command that displays which vendors have codes matching the products table. There fore the data displayed will tell us Which Vendors provide products and which vendors do not. I only need to display the ones that do provide products.

SELECT * FROM vendor where V_CODE = V_CODE FROM product;

I have a pseudo code logic here which is what I am looking for. I want SQL to display All vendors who have a matching V_CODE in both the vendor and products table.

SELECT * FROM vendor where V_CODE = V_CODE FROM product;

This code does not compile because FROM is not in a valid position

Randolph
  • 302
  • 3
  • 12
Vector 2755
  • 37
  • 1
  • 5
  • 1
    Are you using MySQL or SQL Server? – Ilyes Apr 03 '19 at 09:42
  • You should reread your notes on joins. – P.Salmon Apr 03 '19 at 09:42
  • [Joins (SQL Server)](https://learn.microsoft.com/en-us/sql/relational-databases/performance/joins?view=sql-server-2017) & [13.2.10.2 JOIN Syntax](https://dev.mysql.com/doc/refman/8.0/en/join.html) (Search engines are your friend :) ) – Thom A Apr 03 '19 at 09:43

1 Answers1

1

Do join with proper syntax

SELECT * FROM vendor join product
on vendor.V_CODE = product.V_CODE
Fahmi
  • 37,315
  • 5
  • 22
  • 31