How do I SELECT same column name from multiple tables
Discuss coding issues, and scripts related to PHP and MySQL.
-
Marius
- Posts: 107
How do I SELECT same column name from multiple tables
I have 2 tables with same column names in my database which are supposed to provide content in 2 languages.
This is how I query for one table (this query is executed correctly):
Code: Select all
$sql = "SELECT * FROM tab_en WHERE time > $from";
However, when I try to do it for 2 tables:
Code: Select all
$sql = "SELECT * FROM tab_en, tab_es WHERE time > $from";
I am getting the error. What am doing wrong?
MarPlo
Posts: 186
The mysql is confused when you select columns with same name. The solution is to use Alias ( AS ).
Code: Select all
$sql = "SELECT en.col1 AS c1en, en.col2 AS c2en, es.col1 AS c1es, es.col2 AS c2es FROM tab_en AS en, tab_es AS es WHERE time > $from";
- The same technique can be applied when you use JOIN with tables that have columns with same names.
Code: Select all
$sql = "SELECT en.col1 AS c1en, en.col2 AS c2en, es.col1 AS c1es, es.col2 AS c2es FROM tab_en AS en
LEFT JOIN tab_es AS es ON en.id = es.id
WHERE en.time > $from";
Similar Topics
-
Multiple select for upload not working on mobile
JavaScript - jQuery - Ajax
First post
Plessant Coursesweb,
meight useless to ask but it seems this upload for picture-album is not working on my mobile-page
but on my computer I just...
Last post
Try to search on the internet for:
html multiple select upload mobile