473,387 Members | 1,517 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,387 software developers and data experts.

Avoid column duplicate printing in mysql

2
I have a Mysql table that looks like this:
model text(10) the moodel of item
color text(10) the color of item

i have some records:
1) "pippo";"red"
2) "pippo";"yellow"
3) "pippo";"green"
4) "gino";"blue"
4) "gino";"red"
4) "gino";"black"

if i do this query
select name, color from table order by 1,2
I will have this results:
Expand|Select|Wrap|Line Numbers
  1. name           color
  2. gino           black
  3. gino           blue
  4. gino           red
  5. pippo          green
  6. pippo          red
  7. pippo          yellow
  8.  
I would like to have
Expand|Select|Wrap|Line Numbers
  1. name           color
  2. gino           black
  3.                blue
  4.                red
  5. pippo          green
  6.                red
  7.                yellow
  8.  
Is there a mysql whai to have this results?

Thanks!
Dec 10 '12 #1
3 2189
Rabbit
12,516 Expert Mod 8TB
You will need to number the rows and partition it by the name.

If you do not know how to do that, you can use one of these methods:
http://www.xaprb.com/blog/2005/09/27...mber-function/
http://www.xaprb.com/blog/2006/12/02...rows-in-mysql/

You can then use a CASE statement to show the name only if the row number is one.
Dec 10 '12 #2
uffa14
2
Thanks!!
Using the examples in your link I've got what i need!!
Expand|Select|Wrap|Line Numbers
  1. set @type = '';
  2. set @num  = 1;
  3.  
  4. select
  5.    @num := if(@type = type, "", type) as row_number,
  6.    @type := type as dummy,
  7. variety
  8. from fruits;
That give me this results:
Expand|Select|Wrap|Line Numbers
  1. +------------+--------+------------+
  2. | row_number | dummy  | variety    |
  3. +------------+--------+------------+
  4. | apple      | apple  | fuji       |
  5. |            | apple  | gala       |
  6. |            | apple  | limbertwig |
  7. | cherry     | cherry | bing       |
  8. |            | cherry | chelan     |
  9. | orange     | orange | navel      |
  10. |            | orange | valencia   |
  11. | pear       | pear   | bartlett   |
  12. |            | pear   | bradford   |
  13. +------------+--------+------------+
  14.  
  15.  
Dec 11 '12 #3
Rabbit
12,516 Expert Mod 8TB
Glad you got it working, good luck with the rest of your project.
Dec 11 '12 #4

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

Similar topics

1
by: mudge | last post by:
Hello, I have a mysql table. Two columns in the table are used to pull out stories from the table. One of the columns stands for categories of the stories, and the other column is the primary...
0
by: Tiffany Wilkes | last post by:
I solved the problem--I needed ( ) around the column list. I think the manual should make that more clear. -------- Original Message -------- Subject: column privilege problem Date: Tue, 05...
1
by: veg_all | last post by:
i am trying to create a table with a column name called 2004. But I keep getting a mysql error? Is there any workaround? Unable to execute: You have an error in your SQL syntax. Check the manual...
0
by: Keith Lee | last post by:
All: In Oracle, you can set the iinesie and column size so the screen output looks nice and uniform. What are the equivalent commands in Mysql 4.1.1? Thank you. Keith
1
by: charliej2001 | last post by:
Hi all My access database has import/export capabiltiy of contact details between outlook. The database is getting big now (1000+ contacts) and so are the outlook address books that have the...
3
by: beary | last post by:
I picked up the following code to take a mysql table to an excel file. What do I need to do to it to make the first excel row be the column names, rather than the first record? $query = "SELECT *...
8
by: desirocks | last post by:
Hi all, I am somewhat new to sql server. So help me in whatever way you can. I have two tables one of which doesnt have a primary key(table A) and other has a composite key formed of two...
3
by: bnashenas1984 | last post by:
Hi everyone I have a registration page on my website ( PHP ) which users should enter nick name,first name, last name, email, password ,... Each email and nickname should be registered just once....
8
by: Dhiru1009 | last post by:
Hi guys, I have a problem. I have created a login system where user can register their login details before they login to website, to register they have to provide there username,password and...
2
anfetienne
by: anfetienne | last post by:
ive made a piece of coding to work out if a certain column within a db has any values stored in it but i keep getting the else statement for results....i think i may be using the wrong sql function,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.