So I have two tables in my phpmyadmin like
tabel1 and tabel2
in both tables, i want to select id = 2
so I have tried
mysql_query('SELECT * FROM tabel1, table2
WHERE id=2');
but not working plz give me some suggestions
So I have two tables in my phpmyadmin like
tabel1 and tabel2
in both tables, i want to select id = 2
so I have tried
mysql_query('SELECT * FROM tabel1, table2
WHERE id=2');
but not working plz give me some suggestions
4
Answers
You can use UNION ALL to accomplish what you want.
I think you have a typo there. You said you have
table1
andtable2
Then your SQL statement should be
mysql_query('SELECT * FROM table1, table2 WHERE id=2');
instead of
mysql_query('SELECT * FROM tabel1, table2 WHERE id=2');
what was in your question.
Depending on your exact requirements, the query might be as easy as
You are implicitly joining your tables for the condition of
table1.id
andtable2.id
being equal 2.Use inner join and also read Manual