User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Quick MySQL Question Page [1]  
Noen
All American
31346 Posts
user info
edit post

My mind is drawing a blank here, I've been away from this too long

What is the best way to return a set of data like this in MySQL 4.1.x:

table1:

col1 = "foo"
col2 = "bar"

I want to return basically col1 AS col2, which of course you can't do, because damn MySQL only allows static aliases (at least in 4.1) so my result set will look like bar="foo".

So what are the alternatives here? Thanks guys

4/15/2006 2:19:16 PM

qntmfred
retired
40726 Posts
user info
edit post

i think i understand what you're asking but can't figure out why you'd need to do that. can you provide a better example of what you want to do here?

4/15/2006 3:09:20 PM

Noen
All American
31346 Posts
user info
edit post

Like in PHP, where you can assign a variable to be a variable name AKA

$foo="bar";

$$foo = "blah";

makes $bar="blah";

And I'd like to do this because it would make my queries insanely more efficient, since I don't have MySQL 5 as an option and I can't use fucking views.

4/15/2006 3:27:40 PM

Stein
All American
19842 Posts
user info
edit post

SELECT col2 AS x, col1 AS col2

4/15/2006 4:45:26 PM

Noen
All American
31346 Posts
user info
edit post

doesnt work, that just creates a new alias called col2, not the value of col2 as the column name

4/15/2006 5:36:06 PM

Incognegro
Suspended
4172 Posts
user info
edit post

This is generally called indirection, and I'm almost positive SQL doesn't support it. Furthermore, any implementation of it in multiple queries is going to be extremely inefficient. The database probably should be restructured to eliminate the need to do this, because I can't think of any valid reason for a database to be structured like that Variable columns are contrary to the function of a relational database.

4/15/2006 11:34:15 PM

Noen
All American
31346 Posts
user info
edit post

yea, I came up with a solution that should be faster in scale, we'll see how it holds up

Thanks errybody

4/16/2006 11:01:21 PM

 Message Boards » Tech Talk » Quick MySQL Question Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.