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

maximum from columns

i have one table which has 10 columns. all having integer values. and only 1 row.
how can i get the maximum value from amongst the columns in that row.
Mar 22 '07 #1
6 4156
iam_clint
1,208 Expert 1GB
I can't think of any way to do this except serverside scripting.
Mar 22 '07 #2
iburyak
1,017 Expert 512MB
Try this:


[PHP]Select Max(Value)
From (
Select col1 Value, 'Col1' ColumnName from table_name
UNION
Select col2 Value, 'Col2' ColumnName from table_name
UNION
......
) a[/PHP]
Mar 22 '07 #3
AricC
1,892 Expert 1GB
i have one table which has 10 columns. all having integer values. and only 1 row.
how can i get the maximum value from amongst the columns in that row.
In SQL try:
Expand|Select|Wrap|Line Numbers
  1. SELECT MAX(intSomeVariableInteger) FROM TYourTable
  2.  
Mar 23 '07 #4
Thanks this could be a way. But was looking for something generic. We can have any number of columns ..


Try this:


[PHP]Select Max(Value)
From (
Select col1 Value, 'Col1' ColumnName from table_name
UNION
Select col2 Value, 'Col2' ColumnName from table_name
UNION
......
) a[/PHP]
Mar 23 '07 #5
iburyak
1,017 Expert 512MB
It is almost always you have to know table columns in advance.
Union has limitation of 16 so you will have to use something different (like insert into temp table).

To make it generic is possible by using table syscolumns but tell me if you REALLY, REALLY need it so I will not waist my time doing it for you.


Thank you.
Mar 23 '07 #6
Thanks. I needed it last year. It was one of the interview questions therefore wanted a solution. Yes we can use syscolumns to get it. Thanks !!

It is almost always you have to know table columns in advance.
Union has limitation of 16 so you will have to use something different (like insert into temp table).

To make it generic is possible by using table syscolumns but tell me if you REALLY, REALLY need it so I will not waist my time doing it for you.


Thank you.
Mar 7 '08 #7

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

Similar topics

0
by: David.Tymon | last post by:
>Description: MySQL v4.1.0-alpha only allows a client to prepare a maximum of 254 statements. On the 255th mysql_prepare() call, a failure is returned with no information returned by...
8
by: Siemel Naran | last post by:
Hi. I have a table of products and versions, and these 2 columns are the unique key. My challenge is to write a SQL statement to find the latest version of each product. My solutions below...
3
by: Dave Crypto | last post by:
Hi There, SUMMARY: I need to know what the actual maximum date limit possible on a row of a MYSQL database. MORE DETAILS: For example, does a MYSQL database only allow 4032 bytes of data...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
1
by: Alan Foxmore | last post by:
Hello all, Is it possible to use String.Format() to specify a maximum length for a formatted item? For example, let's say I have: String.Format("{0}", "FREDDY"); How can I specify that the...
3
by: ramraj | last post by:
Hello people, I might sound a little bit crazy, but is there any possibility that you can incorporate 4^15 (1,073,741,824) tables into a SQL Database? I mean, is it possible at all? There might...
4
by: kenny | last post by:
hi everybody, i have a question which may be rather trivial to some of you: in my scenario i have three columns with col 1 and 2 holding integers and i want to know the respective maximum for...
1
by: Dilip1983 | last post by:
Hi Experts, 1.What is the maximum number of columns that are permissible to create a table in Oracle? 2. What is the difference between Correlated Subquery and Nested Subquery? Thanks &...
53
by: Gianni Mariani | last post by:
Do you have a preference on maximum line width for C++ code? I've seen the craziest debates on this most silly of topic. I have witnessed engineers spent oodles of time fiddling with line...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.