mahivik Posted November 1, 2010 Share Posted November 1, 2010 Hi all, I am Mahivik and I am starting work in php in my work I am facing a new problem plase tell me if anyone can do my help. I have a database table with filed id, color, fruits, status, in which id is auto increment and primary and i have data in the format. -----|----------------|------------------|----------------| id |color----------| fruits----------|status--------| 1 | yellow ------| banana | 0 | 2 | yellow | mango | 0 | 3 | green | watermalen | 0 | 4 | green | grapes | 0 | 5 | yellow | pineapple | 0 | ----------------------------------------------------------- from this table I have to search fruits name by color but not color group by i.e. select * from fruits group by color, i don't want this. I want result 3 yellow and 2 green. only. Quote Link to comment https://forums.phpfreaks.com/topic/217431-getting-data-from-database/ Share on other sites More sharing options...
Gem Posted November 1, 2010 Share Posted November 1, 2010 COUNT(*) fruits WHERE color="green" COUNT(*) fruits WHERE color="yellow" Quote Link to comment https://forums.phpfreaks.com/topic/217431-getting-data-from-database/#findComment-1128902 Share on other sites More sharing options...
mahivik Posted November 1, 2010 Author Share Posted November 1, 2010 Thanks gemmerz, for your quick responce. bu I want this from single query and number I tryed this select count('yellow') as total_yellow and count("green') as total_green from fruits. but it is not working. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/217431-getting-data-from-database/#findComment-1128906 Share on other sites More sharing options...
Gem Posted November 1, 2010 Share Posted November 1, 2010 Why from one query mate? Quote Link to comment https://forums.phpfreaks.com/topic/217431-getting-data-from-database/#findComment-1128907 Share on other sites More sharing options...
mahivik Posted November 1, 2010 Author Share Posted November 1, 2010 my boss says that, if we make two query then this will make our site slow. actually I make a model of my query I don't want result from this 5 records but I want something more from this. we have around 7000 users list in which we have to select numbers of one type of users. Quote Link to comment https://forums.phpfreaks.com/topic/217431-getting-data-from-database/#findComment-1128908 Share on other sites More sharing options...
Gem Posted November 1, 2010 Share Posted November 1, 2010 Sorry, I think I misread what you wanted to do. I thought you wanted an output like "3 green, 2 yellow" <- You cant do that with one query I dont think Quote Link to comment https://forums.phpfreaks.com/topic/217431-getting-data-from-database/#findComment-1128910 Share on other sites More sharing options...
trq Posted November 1, 2010 Share Posted November 1, 2010 SELECT COUNT(id) as cnt, color FROM tbl GROUP BY color Quote Link to comment https://forums.phpfreaks.com/topic/217431-getting-data-from-database/#findComment-1128917 Share on other sites More sharing options...
mahivik Posted November 1, 2010 Author Share Posted November 1, 2010 Thanks thorpe, It's works, thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/217431-getting-data-from-database/#findComment-1128921 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.