
- You are not logged in. | Login
March 8, 2007 2:52 pm
- mambojim
- Member


Help to set up request to the base
There is a table
code:
id | good | amount | date
1 | 1 | 10 | 2006
2 | 1 | 15 | 2007
3 | 2 | 30 | 2006
3 | 2 | 40 | 2007
It should be got with one request.
code:
good | 2006 | 2007
1 | 10 | 15
2 | 30 | 40
How could it be managed?
Last edited by mambojim (March 8, 2007 2:53 pm)
March 8, 2007 2:57 pm
- sam43inwood
- Member


Re: Help to set up request to the base
The most popular thread is ‘How to get something with one request’. You seem to want nothing else except for ability to form the entire page with one request and reduce the number of requests from 30 to 1.
And the most popular answer is union. It has as much sense as the question does but everyone seems to like it.
March 12, 2007 7:27 am
- IBdaMac
- Member


Re: Help to set up request to the base
mambojim, what do you want to do at all? Do you want to select unique goods or the first entries on them? And what for do you need a year at the top?
Why do you have, for instance, two IDs with the same value?
March 12, 2007 7:31 am
- sam43inwood
- Member


Re: Help to set up request to the base
IBdaMac, two IDs with the same value are an ordinary misprint. She is eager to group goods on years.
March 12, 2007 7:36 am
- cplusplus
- Member


Re: Help to set up request to the base
mambojim, you want to get the same data only structured in other way. It is possible with sql only.
But SELECT * FROM is more readable and more flexible and you are to form what you need by means of PHP.
March 12, 2007 7:39 am
- purplebean
- Member


Re: Help to set up request to the base
First it doesn’t matter if there is a misprint there or not. For purchasing list IDs of buyers may be duplicated.
Second ID duplication doesn’t have any influence upon solution – ID isn’t taken into account in the selection result.
_______________________________________
Now concerning the matter of the fact.
You may ‘restructure’ data as it was mentioned above.
But for each concrete case of ‘transferring columns into rows’ the solution is not trivial and needs individual approach…


