473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

MYSQL - GROUP BY clause at Professional Level

rahulephp
How to fetch the "name" FROM programname = "Buy" and description which has maximum words using GROUP BY??

I have 6 columns with thousands of product entries:
Table name : eproducts
Columns : product_id, programname, name, description, clean_modelno

Ex. Products Entries:

product_id : 5001
programname : argos
name : Toshiba 32RV753B
description : By Toshiba (100 words)
model_number : 32RV753B
price : 549.99

product_id : 5002
programname : Buy
name : Toshiba 32 Inch Full HD 1080p Freeview HD LCD TV
description : Television picture quality: Freeview HD digital (Approx 110 words)
model_number : 32RV753B
price : 499

product_id : 5003
programname : Amazon
name : Toshiba 32 Inch Widescreen Full HD 1080p LCD TV
desciption : 66cm Visible LCD HD Ready Integrated Digital (Approx 90 words)
model_number : 32RV753B
price : 650

product_id : 5004
programname : Ebey
name : 2RV753B 32Inch HD Ready 1080p LC HD Read
description : Toshiba 32RV753 / 32RV753B 32" REGZA RV Serie (Approx 97 words)
model_number : 32RV753B
price : 550

When I Group by the products using there model numbers, it gave me the first row as output as all these four products has same model number:

Expand|Select|Wrap|Line Numbers
  1. SELECT *,  
  2.  
  3. MAX(price) as max_price,
  4.  
  5. MIN(price) as min_price,
  6.  
  7. count(distinct programname) as total_retailers
  8.  
  9. FROM eproducts as e
  10.  
  11. WHERE 
  12. GROUP BY model_number
  13.  

BUT,
I want to get the "name" FROM programname : Buy and description which has maximum words from all four descriptions.

Please suggest me a good and efficient solution.
Oct 15 '10 #1
3 1619
Atli
5,058 Expert 4TB
I'm not clear on what you are trying to achieve. Could you explain better what kind of output you want? An example of the desired output would also be helpful.
Oct 16 '10 #2
Ohh. I am sorry if you couldn't understand.
Let me explain,

Description from argos is always good as compare to buy.
In the same way Argos > buy > amazon > ebay > Next
I want to select Description from argos if present else from buy else from amazon.

It mean,
Code:
Expand|Select|Wrap|Line Numbers
  1. if(programname = Argos )
  2. {
  3.    description = description; //Argos description
  4. }
  5. elseif(programname = buy)
  6. {
  7.   description = description;  //buy's description
  8. }
  9. elseif(programname = amazon )
  10. {
  11.   description = description;  //amazon's description
  12. }
  13. elseif(programname = ebay )
  14. {
  15.   description = description;  //ebay's description
  16. }
  17. else
  18. {
  19. description = description;  //Default Next's description
  20. }
  21. GROUP BY model_number
  22.  
The GROUP BY clause always give me the description from first entry which comes first in the queue whatever it will be.

Please help me out, Will be highly thankful to you.
Oct 16 '10 #3
code green
1,726 Expert 1GB
What about
Expand|Select|Wrap|Line Numbers
  1. WHERE description = description
I don't understand what you are trying to do with GROUP BY
Oct 21 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Karzy | last post by:
I'm having trouble coming up with what I would assume is a rather simple mysql query about retrieving records that haven't been updated after a certain time. Does anyone know of a mysql group...
0
by: Mikolaj J | last post by:
Witam, szukając w dokumentacji mysqla odpowiedzi na moje pytanie trafiłem na taki przykład: SELECT user, MAX(salary) as max_sel FROM tmp GROUP BY user HAVING max_sel = MAX(salary); I...
1
by: windandwaves | last post by:
Hi Folk can someone point me in the direction for a general mysql group? TIA - Nicolaas
2
by: pavlin | last post by:
hi I use to work with mysql but now I need mssql. Can somebody tell my how I canwork around LIMIT to select a number of records so I can display 10 records at a time in stead of all? Thanks
5
by: pechar | last post by:
Hi all, We have a product table in the database. One of the columns is ProductGroup which we use in the case when a product is available in multiple colours say a red, green or blue cap. So if a...
3
by: veer | last post by:
Hi i run this query it works fine Select Yp1VOp,count(*) as instrec into instrec from " & txttablename & " where Yp1EOp=Yp1VOp Group By Yp1EOp,Yp1Vop Order By Yp1EOp,Yp1VOp but when i put a...
4
by: luttkens | last post by:
I have a table salary, and when I select it, it looks like this Name Year Income ------------------------------- James Smith 2008 33000 James Smith 2007 32000 James Smith ...
2
by: gnawz | last post by:
I have a table that consists of 5 categories and each category has items called brands. I want to be able to list the Category of each set of brands on top of the list using PHP and MySQL in...
3
bilibytes
by: bilibytes | last post by:
Hi there, is it possible to pass a PHP array to get some data matching in a Mysql Table? lets say i have a list of names that i get from PHP into an array: $php_array = array(0=>'john',...
2
by: ronparker | last post by:
Hello, I am using python to run mysql commands, however I don't think that should be a problem. When I am trying to select vales from a mysql talbe, I am having some trouble with the where clause. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.