Hello. The question is stupid, but still can not figure it out ...

There are 2 queries from the database:

$result = mysql_query("SELECT * FROM `table1` WHERE id = '$_GET[id]'"); $result2 = mysql_query("SELECT * FROM `table2` WHERE user_id = '$_GET[id]'"); 

How to combine them into one request?

As I understand it, there must be intersecting fields, for example, id in one database should be equal to id in another?
I want to understand how to select data from 2 tables in order not to store all the data needed in one table.

  • 2
    You somehow all in one table 'table' lies. JOIN is used to merge sample results. - Get
  • @Get answered your question. To get a more detailed answer, put a specific question. Also note the comment @ maxspb89. - jackrv
  • Yes Yes. Wrong. Corrected the issue. - Batyabest

2 answers 2

As an option

 SELECT table1.id as 'id_t1', table1.name as 'name_t1', table2.user_id as 'id_t2', table2.name as 'name_t2' FROM table1, table2 WHERE table1.id = '$_GET[id]' AND table2.user_id = '$_GET[id]'; 

But I am sure that this is not a solution, because for some reason it seems that the question will still change in favor of cross-sampling. ;)

In the meantime, keep http://sqlfiddle.com/#!2/c3f38/1

  • At first glance, what you need. Simply, there is user data, and not all of them are stored in the same table. That is so that you can pull this data, based, for example, on the user id. - Batyabest
 "SELECT * FROM table WHERE id = xx AND user_id = yy;" 
  • I fixed the question, I have data in 2 different tables. - Batyabest