tags:

views:

206

answers:

3

I have this elementary query:

SELECT d.description, o.code FROM order_positions AS o
LEFT JOIN article_descriptions AS d ON (o.article_id = d.article_id)
WHERE o.order_id = 1

and I'm using MDB2 from PEAR to execute it and read the return values.

But somehow the result array always contains fields from the order_positions table only!, i.e. the result array looks like this

row[code] = 'abc123'

while I want it to look like this

row[description] = 'my description'
row[code] = 'abc123'

I already tried the following:

  • Vary the order of the fields, i.e. code first, then description.
  • Vary the order of the joined tables.
  • Used full table names instead of aliases.
  • Used the "MySQL join" instead (SELECT FROM table1, table2 WHERE table1.id = table2.id)
  • Used aliases with and without AS.

Some other facts:

  • Executing this query in MySQL Query Browser works fine, all fields are returned.
  • The order_positions table seems to be preferred, no matter what. When joining with additional tables I still only get fields from this table.
A: 

This should work:

SELECT d.description, o.code 
FROM order_positions o, article_descriptions d 
WHERE o.order_id = 1 AND d.article_id = o.article_id
code_burgar
Thanky you, but as I said, I already tried that.
DR
A: 

Are you sure you're not using fetchOne() by mistake instead of fetchRow()?

Could you post your PHP code?

Another possibility is that in your code you missed the comma:

SELECT a b

is the same as

SELECT a AS b
Greg
No, I'm using fetchRow. Wouldn't a missing comma result in a syntax error? I checked also with and without AS, both the same.
DR
+1  A: 
DR