Jump to content

Two tables, count records and filter


corestat.consulting

Recommended Posts

Hello!

 

I'm working on a big project but I can't get any help. I would be very happy if someone could help me out.

 

I have two tables called onkormanyzat and cko. They both have an ID column called ok_id. They also have a telepules (town) and a bemutato_resztv (participated) column which can be 'Igen' or 'Nem'. I would like to get all the telepules (towns) from both cko and onkormanyzat and count the ones which have 'Igen' in participated (bemutato_resztv). But i don't want to have duplicate towns (telepules). It is poosible that only one table has that town with Igen and the other doesnt. So if any of the tables with the selected telepules has 'Igen' it counts.

 

      $query = "SELECT cko.megye,onkormanyzat.ok_id,

      COUNT(cko.ok_id) FROM onkormanyzat JOIN cko ON

      (onkormanyzat.telepules = cko.telepules)

      AND cko.bemutato_resztv='Igen'

      GROUP BY cko.megye";

 

I tried this one, but it only counts the telepules or ok_id (at this time) if both the telepules is in both tables and if cko has bemutato_reszt='Igen'.

 

COUNT telepules from both tables (cko,onkormanyzat) when any of them has bemutato_resztv='Igen' without duplicate telepules.

 

 

 

Thank You!

 

Benedek Rakovics

CoreSTAT Consulting Bt.

Skype: corestat.consulting

 

Link to comment
https://forums.phpfreaks.com/topic/95989-two-tables-count-records-and-filter/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.