1

I'm trying to get login and count that are in different tables but it doesn't work

Here is what I'm doing:

SELECT login AS "Login", COUNT(posted) AS "Nombre" FROM members, wallmsg;

I get the following error:

ERROR 1140 (42000): In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'sc_social.members.login'; this is incompatible with sql_mode=only_full_group_by

Is there another way to do this?

3 Answers3

0

To fetch data from two tables in SQL, you first need to add join between the tables. Whenever you uses any aggregate functions like "Count", you have to use "GroupBy" clause. SELECT m.login,COUNT(w.posted) FROM members m inner join wallmsg w on m.SomeId =w.SomeId group by m.login

Abhishek Sharma
  • 360
  • 1
  • 10
0

You have set sql mode on ONLY_FULL_GROUP_BY, you should change it by:

SET sql_mode = ''

and see this answer for detailed explanation

godot
  • 3,422
  • 6
  • 25
  • 42
0

try something like this:

SELECT
  Orders.OrderID,
  Customers.CustomerName,
  Orders.OrderDate
FROM Orders
  INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
godot
  • 3,422
  • 6
  • 25
  • 42
sandip bharadva
  • 629
  • 1
  • 6
  • 19