Jump to content
php.lv forumi

WHERE IN...


goma smile

Recommended Posts

Iedomājieties datubāzes tabulas kollonā glabājās implodēti id piemēram

 

pattern_id    =  1,2,3,4,5,6,7

 

,bet es vēlos lai vaicājums pārbauda vai pattern_id šūnās norādītā skaitļu virtne sakristu ar kādu no skaitļiem kkā ta

 

WHERE `pattern_id` IN ('6, 5, 4, 3, 2'),
 

Link to comment
Share on other sites

šeit prasās pēc normalizācijas.
Izveido tabulu:
 
objects_patterns
-----
object_id
pattern_id
 
un katram objekta priekš katra paterna izveido ierakstu.
Tālāk atlase jau pavisam vienkārša.
 

SELECT * 
FROM objects_patterns op
LEFT JOIN objects o
ON op.object_id=o.id
WHERE op.pattern_id IN (2,4,6,7,8)
Link to comment
Share on other sites

 

šeit prasās pēc normalizācijas.

Izveido tabulu:

 

objects_patterns

-----

object_id

pattern_id

 

un katram objekta priekš katra paterna izveido ierakstu.

Tālāk atlase jau pavisam vienkārša.

 

SELECT * 
FROM objects_patterns op
LEFT JOIN objects o
ON op.object_id=o.id
WHERE op.pattern_id IN (2,4,6,7,8)

Jā paldies - Cepums atrisināts :)

Link to comment
Share on other sites

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...