Jump to content
php.lv forumi

Recommended Posts

Posted

Tātad kā jau iekš topic title un topic description nopratāt man vajag atlasīt datus no daudzam tabulām, un jautājums ir kā to vislabāk izdarīt?

Man ir šāda situācija ir kopā 10 tabulas, kuras satur datus un katrai no tabulām ir lauks userid.

Un tad nu man vajag atlasīt no šīm 10 tabulām datus kur userid ir vienāds ar kkādu noteikta lietotāja id.

Kā izskatīsies selects?

Posted

Var atlasīt pa daļām, piemēram:

 

$query1 = 'select * from table1 where user_id = '.$id;

$query2 = 'select * from table2 where user_id = '.$id;

$query3 = 'select * from table3 where user_id = '.$id;

...

 

 

Man šķiet, ka var arī salikt visu vienā kverijā:

$query1 = 'select * from table1, table2, table3, table4... where table1.user_id = '.$id.' and table1.user_id = table2.user_id and table1.user_id = table3.user_id and table1.user_id = table4.user_id...';

Posted

Ja atlasāmo lauku skaits ir vienāds, tad var lietot UNION'u:

(SELECT a, b, c FROM table1 WHERE user_id=$id) UNION (SELECT d, e, f FROM table2 WHERE user_id=$id) ...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...