Jump to content
php.lv forumi

Paņemt tikai vienu, nevis katram


Sasa

Recommended Posts

šāds querijs:

SELECT
materialakategorija.IDmaterialaGrupa,
materialakategorija.kategorija
FROM
materialakategorija ,
materials ,
materialaparametrs
WHERE
materialaparametrs.IDmaterials =  materials.IDmaterials 
AND
materials.IDmaterialaKategorija =  materialakategorija.IDmaterialaKategorija

 

tagad izvadās katram materiāla parametram, materiala kategorija pie kura tas pieder.

Bet kā izvadīt tikai tās Materiāla kategorijas kurās ir kaut kāds materiāls + kuram vēl kads parametrs?

Link to comment
Share on other sites

Ja pareizi sapratu jautājumu, tad kaut kā tā:

 

SELECT DISTINCT materialakategorija.IDmaterialaGrupa,
               materialakategorija.kategorija
FROM <tālāk kā tekstā>

 

vai

 

SELECT materialakategorija.IDmaterialaGrupa,
      materialakategorija.kategorija
FROM materialakategorija k
WHERE EXISTS (
 SELECT 1 
 FROM materials, materialaparametrs
 WHERE materialaparametrs.IDmaterials =  materials.IDmaterials 
   AND materials.IDmaterialaKategorija =  k.IDmaterialaKategorija)

 

Gints Plivna

http://datubazes.wordpress.com

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