-1

I have 2 tables.

table2 structure:

  name
  os
  count

table1 structure:

 name

Examples of table2: Fred Android 50 Tom iOS 3 Tom iOS 3 Fred Android 1 Fred Android 1 James iOS 20

Table1 has a list of names (unique).

My current query (stored in PHP variable $sqlx) is

$sqlx = "SELECT COUNT(*) AS numberOfRows FROM table2 where name = 'Fred' AND  count < '6' AND os = 'iOS' GROUP BY name";

How do I make a subquery so that I don't have to enter 'Fred' so that the name is selected from table1?

4

1 回答 1

2

添加 IN 意味着您将检查此列表中的所有项目。然后使用第二个选择查询,您只是从 table1 中提取所有名称。如果需要,您可以在此处施加更多条件。

$sqlx = "SELECT COUNT(*) AS numberOfRows FROM table2 WHERE name IN (SELECT name FROM table1) AND count < '6' AND os = 'iOS' GROUP BY name";
于 2016-04-28T19:01:29.053 回答