tags:

views:

66

answers:

3

Is it poosible to delete just one column in a table when display out?

company name ||  name || year||
____________________________________
walmart      || jason || 1990
___________________________________
walmart      || mary  || 2000

to

company name ||  name || year||
____________________________________
walmart      || jason || 1990
___________________________________
             || mary  || 2000
____________________________________

the data is retrived from database.

+6  A: 

you'll have to do this on the client side.
something like
while CurrentValue == PreviousValue write empty string.

Mladen Prajdic
Yup, this is definitely a client side / presentation issue and does not belong into the database.
Pekka
Your algorithm depends on the tuples being grouped by company name, which is not guaranteed (unless the SQL request used GROUP BY).
bortzmeyer
order is implied from the posters problem. if the rows aren't sorted you can't have such output.
Mladen Prajdic
A: 

You can also do it server side with something like:

SELECT IF(
  IFNULL((SELECT t2.company_name FROM `table` t2 WHERE t1.company_name = t2.company_name AND t2.year < t1.year LIMIT 1), "") = "", company_name,"")
  name, year, FROM `table` t1 ORDER BY company_name, year

I'm no SQL guru, so I guess someone is able to rewrite this to be more efficient, but what I am doing is grabbing the company_name with the sub SELECT, if there is a company_name with with the same name, but a lower year. Then I invert it, by checking the result is NULL (no earlier year available)

Veger
A: 

There are many ways to achieve this in SQL, but that's the wrong place to do do.
This is also a typical feature of reporting tools.

Craig Young