I have a query like this:
SELECT `*`
FROM (`threads` t, `members` m)
WHERE `m`.`id` = t.author
AND `t`.`type` = '0'
AND `t`.`category` = '1'
And basically what happens is that there is an ID field in both tables (members and threads) so what’s happening is that the results array is getting messed up. IE: There is only one ID field which is being populated from the members table.
What I need to do is make the results with a prefix infront of their key name so I can distinguish between the two:
IE: Add ‘t.’ to all thread fields and ‘m.’ to all members fields.
So results should be like: m.id = x, t.id = y
Instead, results at the moment are like: id = x (the id field from the thread table is completely overwritten by the one from the members table)
Use:
Column aliases are defined on a column by column basis – you can’t use wildcards/etc.
You can use the
ASkeyword, or simply enclose the column alias within single quotes if the column name doesn’t contain special characters – use double quotes if it does. You can combine single/double quote usage with theASkeyword.Do I have to List all the Columns?
Yes, you have to list all the columns unless you like duplicate columns because you choose to use
m.*ort.*. There is no convention in SQL that supports what you ask.SELECT *is not an ideal practice – read this answer for details beyond this situation why.Addendum
I took the liberty of rewriting your query to use ANSI-92 JOIN syntax – your example used ANSI-89. There’s no performance difference.