Jump to content
php.lv forumi

no MYSQL izvada tikai tos vardus, kur atkartojas!


dAivEd

Recommended Posts

Sveiks! Man ir tāds jautajums, man datubāze ir:

 

davids

davids

davids

olegs

davids

igors

edgars

davids

ingus

davids

ingus

 

Man vajag lai no datubāzes izvada tikai tos vārdus, kuri atkartojas, lai MYSQL izvada šita:

 

daivds

davids

davids

davids

davids

davids

ingus

ingus

 

utt..

 

Kads var palidzēt ar pieprasijumu lai izvēletos tikai tos vardus kuri atkartojas ?

Link to comment
Share on other sites

Šādi te var atlasīt tikai tos, kas atkārtojas...

 

SELECT name FROM table GROUP BY name 
HAVING COUNT(name) > 1

 

..bet tas gluži nav tas, ko vēlies panākt...

 

 

EDIT:

laikam izštukoju:

 

SELECT * FROM table WHERE name IN (SELECT name FROM table GROUP BY name HAVING COUNT(name) > 1)

 

nav testēts...

Edited by briedis
Link to comment
Share on other sites

Man vajag lai no datubāzes izvada tikai tos vārdus, kuri atkartojas, lai MYSQL izvada šita:

daivds

davids

davids

davids

davids

davids

ingus

ingus

 

utt..

 

Kads var palidzēt ar pieprasijumu lai izvēletos tikai tos vardus kuri atkartojas ?

Kam tev taadu marazmu ???

ja gribi saskaitit cik reizes atkartojas tad izmanto cont(*) + HAVING .. GroupBy

Link to comment
Share on other sites

Šādi te var atlasīt tikai tos, kas atkārtojas...

 

SELECT name FROM table GROUP BY name 
HAVING COUNT(name) > 1

 

..bet tas gluži nav tas, ko vēlies panākt...

 

 

EDIT:

laikam izštukoju:

 

SELECT * FROM table WHERE name IN (SELECT name FROM table GROUP BY name HAVING COUNT(name) > 1)

 

nav testēts...

 

tencinu, un ka man tagad izdzest visus, iznemot 1, lai paliktu

 

davids 1x

 

utt.. ?

Link to comment
Share on other sites

To dara mans pirmais dotais variants - atlasa visus vārdus, kam kopskaits ir > 1...

Mazliet papildinashu

SELECT name, COUNT(name) AS skaits FROM table GROUP BY name HAVING skaits > 1

Shadi varesi dabuut arii skaitu cik tad iisti tas atkartosnas ir

P.S. HAVING COUNT(name) Noaminits pret HAVING skaits jo COUNT(name) jau tiek izmantots pashaa selectaa , un itkaa shadi esot "pareizaak"

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