Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

if then else select problem

[es] :: MySQL :: if then else select problem

[ Pregleda: 2604 | Odgovora: 7 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

kandelabr

Član broj: 139008
Poruke: 13
*.adsl-a-1.sezampro.yu.



Profil

icon if then else select problem03.06.2008. u 12:43 - pre 193 meseci
Zanima me jel moze nekako da se napise sledeci tip upita u mysql:

Code:


  if(uslov) then select * from tabela1 where .... 
  else select * from tabela2 where ...



Hvala unapred na odgovuru.
 
Odgovor na temu

bags

Član broj: 10072
Poruke: 715
*.it-austria.net.



+2 Profil

icon Re: if then else select problem03.06.2008. u 12:58 - pre 193 meseci
Mislim da tako nesto u SQL upitu nije moguce.

Postoji if ali on ti sluzi da manipulises sa dobijenim rezultatima ,mada je i u tom slucaju bolje koristiti CASE jer on je standardan.

Zasto to ti treba u stvari ovako nesto?
Free advice is seldom cheap.
 
Odgovor na temu

kandelabr

Član broj: 139008
Poruke: 13
*.adsl-3.sezampro.yu.



Profil

icon Re: if then else select problem03.06.2008. u 13:08 - pre 193 meseci
Pa razmisljao sam nesto u vezi search, recimo ako se ukucaju 2 reci u search polje pa ako se u nadju obe da se iz baze izbace samo one kolone koje sadrze obe, a ako takvih nema da se onda izbace sve kolone koje sadrze ili jednu ili drugu rec.
 
Odgovor na temu

BluesRocker

Član broj: 20536
Poruke: 1130



+394 Profil

icon Re: if then else select problem03.06.2008. u 13:21 - pre 193 meseci
Mozes sa unijom
Code:

select * from table where field like '%first%' and field like '%second%'
union
select * from table where field like '%first%' or field like '%second%'

Romanes Eunt Domus
 
Odgovor na temu

Schmidt
RHCE

Član broj: 80784
Poruke: 647
*.poen.net.



+10 Profil

icon Re: if then else select problem03.06.2008. u 13:27 - pre 193 meseci
Mislim da cje taj or da napregne bazu, nisam siguran, treba testirati s njim i bez njega.
 
Odgovor na temu

kandelabr

Član broj: 139008
Poruke: 13
*.adsl-3.sezampro.yu.



Profil

icon Re: if then else select problem03.06.2008. u 13:37 - pre 193 meseci

Citat:
BluesRocker: Mozes sa unijom
Code:

select * from table where field like '%first%' and field like '%second%'
union
select * from table where field like '%first%' or field like '%second%'


Da ali ovako ce da izbaci sve kolone koje imaju ili jedno ili drugo, a ja bih hteo da mi izbaci samo one koje imaju oba, ako takve postoje, a tek ako ne onda moze ili jedno ili drugo.
 
Odgovor na temu

BluesRocker

Član broj: 20536
Poruke: 1130



+394 Profil

icon Re: if then else select problem03.06.2008. u 14:33 - pre 193 meseci
A da probas ovako:
Code:

select * from table where field like '%first%' and field like '%second%'
union
select * from table where (field like '%first%' or field like '%second%') and (select count(*) from table where field like '%first%' and field like '%second%') = 0

Ovako nesto ne bih preporucio, mnogo je lepse da se uslov uradi u nekom programskom jeziku.
Romanes Eunt Domus
 
Odgovor na temu

Schmidt
RHCE

Član broj: 80784
Poruke: 647
79.143.168.*



+10 Profil

icon Re: if then else select problem03.06.2008. u 14:36 - pre 193 meseci
prouchi full text search, ima sve shto ti treba u njoj...
 
Odgovor na temu

[es] :: MySQL :: if then else select problem

[ Pregleda: 2604 | Odgovora: 7 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.