Re all,
I need a little help with SQL. I got two SQL queries:
the first one counts how many occurences of a certain condition:
SELECT COUNT(*)
FROM table1
WHERE condition1 = @condition
the second one select each row that match the same condition on the same table joined with a secondary table:
SELECT *
FROM table1 INNER JOIN table2
ON table2.id = table1.id_sub
WHERE condition1 = @condition
Using both these queries in interactive fashion (by code) I can achieve the result I need but I want to optimize the procedure using SQL features instead coding.
What I really need is a query that reports just a single row for each group of rows that matches condition1. I need also to insert the count of the matching rows as a field of the result row.
I'm running MySQL 5.6 and code the application trough Visual Studio 2013 Pro coding in C# (using MySQL.Data package).
Best Regards, WeirdGyn