|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Simple MySQL syntax help
Hi,
Is it possible to have a sort of optional WHERE clause? For example if I have a database of shoes and I search for all size 11 shoes in white (SELECT * FROM shoes WHERE size = 11 AND colour = 'White'), but no size 11 white shoes are available, the SQL would return nothing. But Is there a way to include something in the SQL that sort of says to the database "if there are any white shoes in a size 11, display them all, otherwise just show every other shoe in size 11 nevermind what colour". I apologise for the shoe analogy, it's the only example I could think of. But hopefully you get the idea. Can anyone help me out? |
|
#2
|
|||||
|
|||||
|
Well the closest I can think of is CASE... but I don't know if that is available in MySQL or not. Unfortunately, I use MS-SQL, so all I can tell you is what is available there. Perhaps it will get you started at least. Here is an example:
SQL Code:
Which gives you all white shoes and all size 11 shoes (regardless of color). I know this probably isn't *exactly* what you need, but I hope it helps. ![]()
__________________
Slarentice (origin:Shadow Wizard of ASP Free) [noun] A slave and apprentice of the Wizard's Circle (specifically of mehere) at ASP Free. ---- If shemzilla takes over, it's best to be on his good side ![]()
|
|
#3
|
|||
|
|||
|
Re:Simple MySQL syntax help
Hi,
I hope that the below SQL query will be useful for you..... Code:
if exists(select * from test2 where size= '11' and color = 'white') begin select * from test2 where size= '11' and color = 'white' end else begin select * from test2 where size= '11' end Thanks & Regards Sakthimeenakshi.S |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Simple MySQL syntax help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|