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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.