0

I have a small problem with a MYSQL select query involving an INNER JOIN. Both tables that I'm joining have a field that have identical names. So when I use

$array = mysqli_fetch_array($result,1);
$field = array['fieldname'];

it returns the wrong value from the wrong table.

Is there any way around this?

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by JRM
0

not really a fix but, how about swapping the order of the tables in the query?
When you have conflicts like that, all kinds of confusion can happen.
change the conflicting name if possible, otherwise do two queries in tandem.

0

Thanks for your reply, which is the correct order to select the tables in the query?

And also does anyone know if it is possible to combine SELECT * with an AS query like:

SELECT *, project.status AS pstatus

Edited by ElegantElephant: n/a

0

Thanks for your reply, which is the correct order to select the tables in the query?

And also does anyone know if it is possible to combine SELECT * with an AS query like:

SELECT *, project.status AS pstatus

you never posted the query, but the order depends on the objective and which table needs data from the other to perform the join.

the second question is too vaugue but if :
project = database name and status = table , yes you can alias a table.
the columns are referenced like pstatus.date.
Usually you work omn tables within a database which is already set, so
you just do the alias of the table. i like them short like in the MySql docs.
my_big_table_name AS t1, etc...

Speaking of MySql docs, all of this is there for the reading in much more depth.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.