Count entries from second Table that match id from first Table

user1610904

This is basic but I can't figure it out. I have two tables (SeriesTable and OtherTable). SeriesTable has all the information for a given series including its id (column named "seriesid"). And OtherTable has a column called "seriescolumn" which also has the ids of a given series.

I need to make a query that counts every entry in OtherTable's "seriescolumn" that matches the seriesid column in SeriesTable. So for example, if the seriesid in SeriesTable is 5, I need to count how many entries in OtherTable have the value of 5 in the seriescolumn.

Below is my current code that simply grabs the info from the first table, but I have no idea how to correctly count the matching entries from OtherTable.

    <?
    $rs= mysql_query("SELECT seriesid FROM SeriesTable ORDER BY seriesid DESC");
    while ($row= mysql_fetch_array($rs)) { ?>

    content

    <? } ?>
Cheruvian

Sounds like you are going to need a join and group by statement.

SELECT  s.seriesid, Count(*) As NumberOfSeries
FROM    SeriesTable s Join
        OtherTable o On s.seriesid = o.seriescolumn
Group By s.seriesid
ORDER BY seriesid DESC

This should return each seriesid and a count of how many times it was repeated.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to make two entries of second table as two columns for a select query from first table?

From Dev

PostgreSQL count entries from one table for a given id and mutliple that by rates in another table and sum it all up

From Dev

PostgreSQL count entries from one table for a given id and mutliple that by rates in another table and sum it all up

From Dev

How to get name from second table by referring to an ID from first table?

From Dev

Get the unique number of entries in column two from table two, where the first column of both tables match

From Dev

linq order by from second table count

From Dev

MySQL Count and SUM from second table with group by

From Dev

Postgresql: Select from first table or replace with data from second table

From Dev

Postgresql: Select from first table or replace with data from second table

From Dev

How to select from first table if ID exist in second or third table with high efficiency?

From Dev

Oracle :Matching row from first and second table

From Dev

I want fetch data from second table if not present in first table

From Dev

Find Top 1000 entries along with count and rank from table

From Dev

Getting the first unused Id from a table?

From Dev

Get Id from first table in transaction

From Dev

Mysql - sql How to get min time and max time record from second table which is include first table id

From Dev

Select all values from first table and ONLY first value from second table

From Dev

Get id from table 1 to match with table 2

From Dev

get name from one table with match id in another table?

From Dev

Sql match id's with names from a table that matches with another table

From Dev

SELECT rows from a table that don't have related entries in a second table

From Dev

Select count(*) from table where (multiple id) in (table)

From Dev

MySQL: Return row count from second table using one query

From Dev

Selecting entries from a table based on another table

From Dev

MySql: insert into table SELECT from another table where first_table ID =another_table.id

From Dev

MySQL SELECT all from first table and join matched data from second table with specific where clause for second table filter

From Dev

Select second record from table matching with first record

From Dev

select a random record from a table, why is first slowly than second?

From Dev

MySQL CodeIgniter Select or not from second table based on column of first Select

Related Related

  1. 1

    How to make two entries of second table as two columns for a select query from first table?

  2. 2

    PostgreSQL count entries from one table for a given id and mutliple that by rates in another table and sum it all up

  3. 3

    PostgreSQL count entries from one table for a given id and mutliple that by rates in another table and sum it all up

  4. 4

    How to get name from second table by referring to an ID from first table?

  5. 5

    Get the unique number of entries in column two from table two, where the first column of both tables match

  6. 6

    linq order by from second table count

  7. 7

    MySQL Count and SUM from second table with group by

  8. 8

    Postgresql: Select from first table or replace with data from second table

  9. 9

    Postgresql: Select from first table or replace with data from second table

  10. 10

    How to select from first table if ID exist in second or third table with high efficiency?

  11. 11

    Oracle :Matching row from first and second table

  12. 12

    I want fetch data from second table if not present in first table

  13. 13

    Find Top 1000 entries along with count and rank from table

  14. 14

    Getting the first unused Id from a table?

  15. 15

    Get Id from first table in transaction

  16. 16

    Mysql - sql How to get min time and max time record from second table which is include first table id

  17. 17

    Select all values from first table and ONLY first value from second table

  18. 18

    Get id from table 1 to match with table 2

  19. 19

    get name from one table with match id in another table?

  20. 20

    Sql match id's with names from a table that matches with another table

  21. 21

    SELECT rows from a table that don't have related entries in a second table

  22. 22

    Select count(*) from table where (multiple id) in (table)

  23. 23

    MySQL: Return row count from second table using one query

  24. 24

    Selecting entries from a table based on another table

  25. 25

    MySql: insert into table SELECT from another table where first_table ID =another_table.id

  26. 26

    MySQL SELECT all from first table and join matched data from second table with specific where clause for second table filter

  27. 27

    Select second record from table matching with first record

  28. 28

    select a random record from a table, why is first slowly than second?

  29. 29

    MySQL CodeIgniter Select or not from second table based on column of first Select

HotTag

Archive