0

I have two tables in MySQL taba and tabb.

I am using mysqli with PHP

The qry stmnt is $result = $this->$conn->query(select * from taba inner join tabb on colx=coly );

The rows returned are correct however I am not getting all the columns back.

In taba I have cola and colb and ALSO in tabb I have cola and colb.

$result is only returning cola and colb. I was hoping for something like taba.cola, taba.colb, tabb.cola and tabb.colb

I have a work around hack where I have renamed all the columns to Acola, Acolb in taba, Bcola, and Bcolb in tabb but surely this can't be right.

Isn't there some way of referring to these columns properly with a qualified table name.

Dharman
  • 30,962
  • 25
  • 85
  • 135
joe_evans
  • 120
  • 5
  • How do you know it does not return all the columns? How did you fetch the records from `$result`? What you got and what you expected to get? – AterLux Oct 19 '20 at 22:00
  • I issued a var_dump and in the array I only got returned a mixture UNIQUE column names !! E.G in tabA = cola, colb, colc in tabB = cola, colb, cold. All I was returned was... cola, colb, colc, cold – joe_evans Oct 19 '20 at 22:29
  • 1
    Can you post the source code? Looks like you're fetching an associative array, instead of number-indexed arrays. – AterLux Oct 19 '20 at 22:35
  • Thanx Dharman Yes you found it - I searched over 50 stackoverflow answers but missed this one. @Paulo Bergantino's answer was the one that I can use and that is to alias column names. I didnt realise I could do this. So on the select I now do select from tabA tabA.colA as tabA_colA. Thanks everyone. It seems that the fault(!) lies in php as it silently removes any duplicate array names on the row return. THANK YOU :¬) – joe_evans Oct 20 '20 at 09:33

0 Answers0