|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL help please
Hi,
I'm a little stuck with this query I'm working with. I'm trying to return products that have a value in one or both of two fields. If there is a value in both fields, return this product twice. Here is a lame example: If the product is a fruit, return its number. or If its a vegetable, return its number. or If its both, then return its number twice. Can this be done in one query? This is probably something simple but I cant seem to figure it out. Thanks, for the help! |
|
#2
|
|||
|
|||
|
return number twice? as in same row?
Code:
select case
when (p.veg= '1'
and p.fru = '1')
then p.id + ',' + p.id
else
p.id
end
from products as p
|
|
#3
|
|||
|
|||
|
ya, the row would return twice
|
|
#4
|
||||
|
||||
|
select productnumber from products
where fruit='yes' UNION ALL select productnumber from products where vegetable='yes' UNION ALL returns all rows from both selects, where UNION would have eliminated the dupe rudy http://r937.com/ |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > SQL help please |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|