0

I'm fetching the column 'toggle' in a LEFT JOIN as a trigger to determine whether or not to use another column on the output side.

So I have this as an example:

SELECT *,o.toggle,t.toggle from teams t
LEFT JOIN team o
ON (joining clause)

Toggle either equals 1 or IS NULL.

The problem is in the output

I can't echo $row['o.toggle'] and $row['t.toggle'].

It has to be $row['toggle'].

The second one overrides the first. How do I differentiate those to use them?

Even assigning them variables doesn't help. It doesn't allow me to use the reference letter o or t.

If it's NULL and NULL, that's fine.

If it's 1 and 1, that's fine too.

If it's 1 and 0, 0 wins.

If it's 0 and 1, 1 wins.

I need to be able to use o.toggle and t.toggle.

Phil
  • 157,677
  • 23
  • 242
  • 245
Jwrbloom
  • 15
  • 4
  • 1
    You want to use aliases. There will be a duplicate question for this but TL;DR ~ `SELECT o.toggle AS oToggle, t.toggle AS tToggle` – Phil Apr 01 '20 at 23:08
  • Does this answer your question? [How to resolve ambiguous column names when retrieving results?](https://stackoverflow.com/questions/431391/how-to-resolve-ambiguous-column-names-when-retrieving-results) – Phil Apr 01 '20 at 23:10
  • Thank you! I didn't realize you could use aliases for columns too. – Jwrbloom Apr 01 '20 at 23:23
  • You're welcome. Good luck with the rest of your project – Phil Apr 01 '20 at 23:37

0 Answers0