[mysql] kilka zapytań razem

0

cześć



select usr_name, usr_text 
from users where usr_id = $user;

select m_title, m_text
from admin_info inner join message on m_a_id = a_id 
where  a_to_usr = $user and m_data_read is null
limit 1;

jak to połączyć w 1 zapytanie ale bez inner joina czy left joina??

0

może lepszy przykład

select go_in1, go_in2 from objects where go_id < 10;  //to jako zmienna 1

select  go_in1, go_in2 from objects where go_id > 10; //to jako zmienna 2

myślałem żeby robić select as ale nie wiem jak zważywszy na 2 różne warunki where

0

sooorry nie zauważyłem tematu niżej, do kosza z tym :)

0

matko jedyna, jednak porażka

bardzo przepraszam za spam, może ktoś to w 1 posta połączyć?

temat jednak aktualny

0

A konkretnie, to co chcesz zrobić?

0

miedzu selectami wstaw union
czyli

select usr_name, usr_text
from users where usr_id = $user;

UNION

select m_title, m_text
from admin_info inner join message on m_a_id = a_id
where a_to_usr = $user and m_data_read is null
limit 1;

0

to nie zadziała ale mniej więcej chciałbym zrobić tak:

$sql = 'select go_in1, go_in2 from objects where go_id < 10 as zmienna1, 
select  to_in1, to_in2 from tobjects where to_id > 10 as zmienna2';

$result = mysql_query($sql);

while($row = mysql_fetch_array($result))
{
   //taki zapis troche teoretyczny   
   if ($row['zmienna1->go_in1'] == 1) { echo "blabla"; } 
   if ($row['zmienna2->to_in2'] == 100) { echo "blablaaaa"; } 
}

czyli mamy 2 różne tabele z różnymi kolumnami i różnymi warunkami where :)
czy to da radę w 1 zapytanie połączyć tak, aby odwołać się tak jak w tych ifach?

0
select go_in1, go_in2, 1 as zmienna from objects where go_id < 10
union all
select  to_in1, to_in2, 2 as zmienna from tobjects where to_id > 10

lub

select go_in1, go_in2, null as to_in2 from objects where go_id < 10
union all
select  to_in1, null, to_in2 from tobjects where to_id > 10

1 użytkowników online, w tym zalogowanych: 0, gości: 1