Welcome Guest, Not a member yet? Register   Sign In
Mysql query question
#3

[eluser]slowgary[/eluser]
Edit: Well, I stand corrected (I'm actually sitting)

I think the join is the only way. You could use 2 queries. Think about what you're asking for, how would mysql return that data?

If it COULD return a row like that, what would the code look like to get that data?

E.g.
Code:
while($person = mysql_fetch_array($results))
{
     echo $person['name'] . $person['job1'] . $person['job2'] ... $person['job54'];
}

See what I mean? You wouldn't have a definite number of fields.

Basically, you're asking for vertical data in a horizontal format. Mysql wouldn't have identifiers for all those fields. Even if you could use the AS keyword, you'd need to supply mysql with a pattern to use for naming.

There may be something you could do with stored procedures, but wouldn't it be so much easier just to issue two queries? One for the person, and one for their jobs.

In an ideal world, you'd never need a table like that - one job for each person.[/b]I think the join is the only way. You could use 2 queries. Think about what you're asking for, how would mysql return that data?

If it COULD return a row like that, what would the code look like to get that data?

E.g.
Code:
while($person = mysql_fetch_array($results))
{
     echo $person['name'] . $person['job1'] . $person['job2'] ... $person['job54'];
}

See what I mean? You wouldn't have a definite number of fields.

Basically, you're asking for vertical data in a horizontal format. Mysql wouldn't have identifiers for all those fields. Even if you could use the AS keyword, you'd need to supply mysql with a pattern to use for naming.

There may be something you could do with stored procedures, but wouldn't it be so much easier just to issue two queries? One for the person, and one for their jobs.

In an ideal world, you'd never need a table like that - one job for each person.


Messages In This Thread
Mysql query question - by El Forum - 05-28-2009, 04:23 PM
Mysql query question - by El Forum - 05-28-2009, 05:35 PM
Mysql query question - by El Forum - 05-28-2009, 05:42 PM
Mysql query question - by El Forum - 05-29-2009, 11:48 AM
Mysql query question - by El Forum - 05-29-2009, 01:19 PM
Mysql query question - by El Forum - 05-29-2009, 10:19 PM
Mysql query question - by El Forum - 05-30-2009, 04:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB