Page 1 of 1

reference a tables field by its index

Posted: Wed May 24, 2006 3:26 pm
by kendall
Hey,

is there any way you can reference a table's field/ column name by the index its is in the list of the table's field

e.g.

I'm trying to select rows from $table left join another table on another tables id = the $table's id

$table is a variable populated from a list...

is there a MYSQL_FIELD_OFFSET(0,$table) thingy?

Kendall

Posted: Wed May 24, 2006 3:37 pm
by Burrito
if you already know the field names, just join on those.

if you need to find the keys, you can run a query like this:

Code: Select all

SHOW KEYS FROM `tablename`

Posted: Wed May 24, 2006 3:42 pm
by kendall
Burrito wrote:if you already know the field names, just join on those.

if you need to find the keys, you can run a query like this:

Code: Select all

SHOW KEYS FROM `tablename`
Sorta kinda but if im using a single statement and i just need to condition 1 field which is the first field isnt there a way to write the "FIRST_FIELD" of the table in question at the time.?
uhm....Spockulator?
wieerd 8O

Posted: Wed May 24, 2006 3:53 pm
by Burrito
hmm...I'm not sure if you can reference a field by an index (ie [0]) in a sql query. You could do it with a subquery for sure if you're using 4.1 or higher.