Connecting Tech Pros Worldwide Forums | Help | Site Map

mysql_query where name unknown

Oak Hall
Guest
 
Posts: n/a
#1: Sep 27 '05
I have a several tables the primary index field name in different in each
one, how do I query with a 'where "column 1" = 3' if I do not know the name
of that column only that it is the first field?? Thanks
Oak



Oli Filth
Guest
 
Posts: n/a
#2: Sep 27 '05

re: mysql_query where name unknown


Oak Hall said the following on 27/09/2005 18:33:[color=blue]
> I have a several tables the primary index field name in different in each
> one, how do I query with a 'where "column 1" = 3' if I do not know the name
> of that column only that it is the first field?? Thanks
> Oak
>
>[/color]

Execute the following MySQL statement:

SHOW COLUMNS FROM table

(where 'table' is the name of the table in question).

The result-set will be a list of the columns from that table.

--
Oli
Oak Hall
Guest
 
Posts: n/a
#3: Sep 27 '05

re: mysql_query where name unknown


thanks will use that

"Oli Filth" <catch@olifilth.co.uk> wrote in message
news:nuf_e.624$Nv6.443@newsfe6-win.ntli.net...[color=blue]
> Oak Hall said the following on 27/09/2005 18:33:[color=green]
>> I have a several tables the primary index field name in different in each
>> one, how do I query with a 'where "column 1" = 3' if I do not know the
>> name of that column only that it is the first field?? Thanks
>> Oak
>>
>>[/color]
>
> Execute the following MySQL statement:
>
> SHOW COLUMNS FROM table
>
> (where 'table' is the name of the table in question).
>
> The result-set will be a list of the columns from that table.
>
> --
> Oli[/color]


Dikkie Dik
Guest
 
Posts: n/a
#4: Sep 28 '05

re: mysql_query where name unknown


Oak Hall wrote:[color=blue]
> I have a several tables the primary index field name in different in each
> one, how do I query with a 'where "column 1" = 3' if I do not know the name
> of that column only that it is the first field?? Thanks
> Oak
>
>[/color]
In the special case you would read the entire record, you could also use
the HANDLER statement.
HANDLER <table name> OPEN AS <handle name>;
HANDLER <handle name> READ `PRIMARY`=3;

It is wise to close the handle later with HANDLER <handle name> CLOSE;

Best regards
Colin Fine
Guest
 
Posts: n/a
#5: Sep 29 '05

re: mysql_query where name unknown


Oak Hall wrote:[color=blue]
> I have a several tables the primary index field name in different in each
> one, how do I query with a 'where "column 1" = 3' if I do not know the name
> of that column only that it is the first field?? Thanks
> Oak
>
>[/color]
Does SQL (or MySQL) specify that the order of columns is a table is
invariant?

Colin
Closed Thread