Get data from one table by reference of another table's column's count(*)

Csharp

I have two tables "domaininfo"" and "Events".domain info has the column name "city" in the same way table name "events" has the column name "city".In this case I want fetch the data from domainname where in events there are the record >200.I want the record which are more then 200 in from domainname reference to city in both table. menace The reference city names in "evets" table morethan 200 which are already in domainname.I tried this queries.

Table Structure of Domaininfo ID City state Country

Table Structure of Events EventName Address City Description

City column has Cities in "domaininfo" table from which in can the reference to fetch the events.So i want the record from "domianinfo" of those cities which have the events in the "events" table more than 200.

For Example: domain info has city name "New York"
             in that case i want to check whether there are the events more than 200 in the "events" table.If "events" table will have the records more than less than 200 it will give me the record from "domaininfo" table.

select count(*) 
  from wpcommon.domaininfo 
 inner join events by city
HAVING COUNT(evets)>200;

select count(*) 
  from wpcommon.domaininfo
  where wpcommon.evets
 having count(*)>200;

select count(*)
 from wpcommon.domaininfo
where wpcommon.evets.select count(*)>200;
O. Jones

Let's build this up, taking advantage of the S in SQL (structured).

First, for what values of city are there more than 200 events?

SELECT COUNT(*) AS eventcount,
       city
  FROM events
 GROUP BY city
HAVING COUNT(*) > 200

That subquery produces the list of cities you want.

Next, let's join that to your list of events.

SELECT d.something,
       d.somethingelse,
       d.whatever,
       d.whatelse
  FROM domaininfo AS d
  JOIN (
        SELECT COUNT(*) AS eventcount,
               city
          FROM events
         GROUP BY city
        HAVING COUNT(*) > 200
       ) AS big ON d.city = big.city

That structured (nested) query will yield the result you hope for.

But beware, the city name by itself isn't guaranteed unique in the USA. Consider "Kansas City" which exists in both the state of Kansas and Missouri. You may want to work with the city/state combination, or with the id.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

set a value to column in one table with another table's column data

From Dev

Fetch data from Table 1 column's count in Table 2

From Dev

select data from one column based on another column's condition in the same table and insert that resulting data to another table

From Dev

Copying data from one server table to another server's table

From Dev

Insert id's from one table to another based on another column

From Dev

Adding data from a column to another table's column Laravel 5.2

From Dev

MySQL compare column from one table to another column in another database's table

From Dev

Update table's column with values from another table's column

From Dev

insert data from one table to a single column another table with no relation

From Dev

Connect collection of rows from one table to another table's column - SQL Server

From Dev

How to get records from one table which are not in another table's fields (3)

From Dev

Get count from another table

From Dev

SQL Server: How substract rows of one column from rows of another table's column

From Dev

Selecting data from table using another table's data

From Dev

How to copy data from one database/table to another Remote one by it's Ip

From Dev

How to create a dynamic table from another table's data in SQL

From Dev

Oracle Temporary table columns and data from another table's rows

From Dev

How to reference a table's "Total Row" value from another sheet?

From Dev

How to compare one table's column against another?

From Dev

Select from one table and count from another

From Dev

Copying data from one table to another different column names

From Dev

Procedure to insert data from one column into two columns in another table

From Dev

Moving some data from one column of MySQL table to another

From Dev

Add column to table with data from another table

From Dev

Update a column of NAs in one data table with the value from a column in another data table

From Dev

Append data from one table to another table

From Dev

Copy Data from one table to another table

From Dev

data.table reference column in another data.table by name

From Dev

Join two columns in one table to a column in another reference table

Related Related

  1. 1

    set a value to column in one table with another table's column data

  2. 2

    Fetch data from Table 1 column's count in Table 2

  3. 3

    select data from one column based on another column's condition in the same table and insert that resulting data to another table

  4. 4

    Copying data from one server table to another server's table

  5. 5

    Insert id's from one table to another based on another column

  6. 6

    Adding data from a column to another table's column Laravel 5.2

  7. 7

    MySQL compare column from one table to another column in another database's table

  8. 8

    Update table's column with values from another table's column

  9. 9

    insert data from one table to a single column another table with no relation

  10. 10

    Connect collection of rows from one table to another table's column - SQL Server

  11. 11

    How to get records from one table which are not in another table's fields (3)

  12. 12

    Get count from another table

  13. 13

    SQL Server: How substract rows of one column from rows of another table's column

  14. 14

    Selecting data from table using another table's data

  15. 15

    How to copy data from one database/table to another Remote one by it's Ip

  16. 16

    How to create a dynamic table from another table's data in SQL

  17. 17

    Oracle Temporary table columns and data from another table's rows

  18. 18

    How to reference a table's "Total Row" value from another sheet?

  19. 19

    How to compare one table's column against another?

  20. 20

    Select from one table and count from another

  21. 21

    Copying data from one table to another different column names

  22. 22

    Procedure to insert data from one column into two columns in another table

  23. 23

    Moving some data from one column of MySQL table to another

  24. 24

    Add column to table with data from another table

  25. 25

    Update a column of NAs in one data table with the value from a column in another data table

  26. 26

    Append data from one table to another table

  27. 27

    Copy Data from one table to another table

  28. 28

    data.table reference column in another data.table by name

  29. 29

    Join two columns in one table to a column in another reference table

HotTag

Archive