-3

I have 3 Tables:

Linked tables

And i want this result:

result

I try with order by but, it did not work, Someone have an idea

Ferdinand Gaspar
  • 2,043
  • 1
  • 8
  • 17
  • 1
    See [Why should I provide an MCVE for what seems to me to be a very simple SQL query](http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query) – Strawberry Aug 27 '17 at 22:41
  • 1
    What did you actually try? Can you post the exact SQL statement you used? – joanolo Aug 27 '17 at 23:06

2 Answers2

1

You can do an INNER JOIN with GROUP BY, e.g.:

SELECT s.number AS supplier, c.category AS category, s.date as `date`, COUNT(r.*)
AS total
FROM supplier s JOIN register r ON s.id = r.supplier_id
JOIN category c ON c.id = r.category_id
GROUP BY s.number, c.category, s.date;
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
0

Assuming the Linked Server name is [LinkedSample\Tables] Then you can use the code below:

SELECT s.number AS supplier, c.category AS category, s.date as `date`, COUNT(r.*) AS total
FROM  [LinkedSample\Tables].supplier s 
JOIN [LinkedSample\Tables].register r ON s.id = r.supplier_id 
JOIN [LinkedSample\Tables].category c ON c.id = r.category_id
GROUP BY s.number, c.category, s.date;