corestat.consulting Posted March 13, 2008 Share Posted March 13, 2008 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted March 13, 2008 Share Posted March 13, 2008 That looks hungarian. What's the relationship between the two tables? Quote Link to comment Share on other sites More sharing options...
corestat.consulting Posted March 13, 2008 Author Share Posted March 13, 2008 Yes it's hungarian There is no relationship between the two tables in PHP. There are records which have the same name: telepules, ok_id, bemutato_resztv, megye Quote Link to comment Share on other sites More sharing options...
fenway Posted March 13, 2008 Share Posted March 13, 2008 Then you need to UNION these two tables, and then count on the "merged" result. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.