reference a tables field by its index

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

reference a tables field by its index

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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`
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
Post Reply