Bluehost.com Web Hosting $6.95

Problem with a query

This is a discussion on Problem with a query within the MySQL Database forums, part of the Database Forums category; I have the following query: SELECT TRIM( trade_game_pieces.id ) AS id, TRIM( from_user.name ) AS from_user_name, TRIM( to_user.name ) AS ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-01-2006
Christoph
 
Posts: n/a
Default Problem with a query

I have the following query:

SELECT
TRIM( trade_game_pieces.id ) AS id,
TRIM( from_user.name ) AS from_user_name,
TRIM( to_user.name ) AS to_user_name,
TRIM( games.game_name ) AS game_name,
TRIM( sets.set_name ) AS set_name,
TRIM( game_pieces.piece_name ) AS piece_name,
TRIM( trade_game_pieces.trade_direction ) AS trade_direction,
TRIM( trade_game_pieces.number_to_trade ) AS number_to_trade
FROM
trade_game_pieces
INNER JOIN game_pieces ON game_pieces.id = trade_game_pieces.game_piece_id
INNER JOIN games_sets ON games_sets.id = game_pieces.games_set_id
INNER JOIN sets ON sets.id = games_sets.set_id
INNER JOIN games ON games.id = games_sets.game_id
INNER JOIN trades ON trades.id = trade_game_pieces.trade_id
INNER JOIN users from_user ON from_user.id = trades.from_user_id
INNER JOIN users to_user ON to_user.id = trades.to_user_id;

and whenever I try to run it I get the following error:

ERROR 1054 (42S22): Unknown column 'from_user.name' in 'field list'

Why? Is it because I'm using an alias table name in a function? If so, is
there a work around?

mysql> select version();
+------------+
| version() |
+------------+
| 5.0.18-log |
+------------+
1 row in set (0.00 sec)

thnx,
Christoph


Reply With Quote
  #2 (permalink)  
Old 12-02-2006
strawberry
 
Posts: n/a
Default Re: Problem with a query


Christoph wrote:
> I have the following query:
>
> SELECT
> TRIM( trade_game_pieces.id ) AS id,
> TRIM( from_user.name ) AS from_user_name,
> TRIM( to_user.name ) AS to_user_name,
> TRIM( games.game_name ) AS game_name,
> TRIM( sets.set_name ) AS set_name,
> TRIM( game_pieces.piece_name ) AS piece_name,
> TRIM( trade_game_pieces.trade_direction ) AS trade_direction,
> TRIM( trade_game_pieces.number_to_trade ) AS number_to_trade
> FROM
> trade_game_pieces
> INNER JOIN game_pieces ON game_pieces.id = trade_game_pieces.game_piece_id
> INNER JOIN games_sets ON games_sets.id = game_pieces.games_set_id
> INNER JOIN sets ON sets.id = games_sets.set_id
> INNER JOIN games ON games.id = games_sets.game_id
> INNER JOIN trades ON trades.id = trade_game_pieces.trade_id
> INNER JOIN users from_user ON from_user.id = trades.from_user_id
> INNER JOIN users to_user ON to_user.id = trades.to_user_id;
>
> and whenever I try to run it I get the following error:
>
> ERROR 1054 (42S22): Unknown column 'from_user.name' in 'field list'
>
> Why? Is it because I'm using an alias table name in a function? If so, is
> there a work around?
>
> mysql> select version();
> +------------+
> | version() |
> +------------+
> | 5.0.18-log |
> +------------+
> 1 row in set (0.00 sec)
>
> thnx,
> Christoph


this doesn't look right:

INNER JOIN users from_user ON from_user.id = trades.from_user_id
INNER JOIN users to_user ON to_user.id = trades.to_user_id;

perhaps it should be:

INNER JOIN from_user ON from_user.id = trades.from_user_id
INNER JOIN to_user ON to_user.id = trades.to_user_id;

Reply With Quote
  #3 (permalink)  
Old 12-03-2006
Paul Lautman
 
Posts: n/a
Default Re: Problem with a query

strawberry wrote:
> Christoph wrote:
>> I have the following query:
>>
>> SELECT
>> TRIM( trade_game_pieces.id ) AS id,
>> TRIM( from_user.name ) AS from_user_name,
>> TRIM( to_user.name ) AS to_user_name,
>> TRIM( games.game_name ) AS game_name,
>> TRIM( sets.set_name ) AS set_name,
>> TRIM( game_pieces.piece_name ) AS piece_name,
>> TRIM( trade_game_pieces.trade_direction ) AS trade_direction,
>> TRIM( trade_game_pieces.number_to_trade ) AS number_to_trade
>> FROM
>> trade_game_pieces
>> INNER JOIN game_pieces ON game_pieces.id =
>> trade_game_pieces.game_piece_id INNER JOIN games_sets ON
>> games_sets.id = game_pieces.games_set_id
>> INNER JOIN sets ON sets.id = games_sets.set_id
>> INNER JOIN games ON games.id = games_sets.game_id
>> INNER JOIN trades ON trades.id = trade_game_pieces.trade_id
>> INNER JOIN users from_user ON from_user.id = trades.from_user_id
>> INNER JOIN users to_user ON to_user.id = trades.to_user_id;
>>
>> and whenever I try to run it I get the following error:
>>
>> ERROR 1054 (42S22): Unknown column 'from_user.name' in 'field list'
>>
>> Why? Is it because I'm using an alias table name in a function? If
>> so, is there a work around?
>>
>> mysql> select version();
>> +------------+
>>> version() |

>> +------------+
>>> 5.0.18-log |

>> +------------+
>> 1 row in set (0.00 sec)
>>
>> thnx,
>> Christoph

>
> this doesn't look right:
>
> INNER JOIN users from_user ON from_user.id = trades.from_user_id
> INNER JOIN users to_user ON to_user.id = trades.to_user_id;
>
> perhaps it should be:
>
> INNER JOIN from_user ON from_user.id = trades.from_user_id
> INNER JOIN to_user ON to_user.id = trades.to_user_id;


It could be correct he could be doing 2 joins to the users tabe under
separate aliases.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:13 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0