Kom ihåg mig?
Home Menu

Menu


Någon som är bra på sql

Ämnesverktyg Visningsalternativ
Oläst 2005-09-29, 21:58 #1
vco-systemss avatar
vco-systems vco-systems är inte uppkopplad
Mycket flitig postare
 
Reg.datum: Dec 2004
Inlägg: 774
vco-systems vco-systems är inte uppkopplad
Mycket flitig postare
vco-systemss avatar
 
Reg.datum: Dec 2004
Inlägg: 774
Jag har följande kodsnutt i en sökfunktion.
Hur kan jag fixa så att jag varje "page_id" bara finns en gång i resultatet?

Kod:
SELECT nuke_paged_content.page_id AS page_id, nuke_paged_content.subtitle AS subtitle, nuke_paged_content.text AS text, nuke_paged_titles.title AS title, nuke_paged_titles.ingress AS ingress, nuke_paged_titles.topic_id AS topic_id
FROM nuke_paged_content
LEFT JOIN nuke_paged_titles ON ( nuke_paged_content.page_id = nuke_paged_titles.page_id ) 
WHERE (
nuke_paged_content.subtitle
LIKE "%sökord%" OR nuke_paged_titles.title
LIKE "%sökord%" OR nuke_paged_titles.ingress
LIKE "%sökord%" OR nuke_paged_content.text
LIKE "%sökord%"
)
Finns det något enkelt sätt eller måste jag "parsa" resultatet i efterhand?
vco-systems är inte uppkopplad   Svara med citatSvara med citat
Oläst 2005-09-29, 22:11 #2
chrizzs avatar
chrizz chrizz är inte uppkopplad
Medlem
 
Reg.datum: Aug 2004
Inlägg: 296
chrizz chrizz är inte uppkopplad
Medlem
chrizzs avatar
 
Reg.datum: Aug 2004
Inlägg: 296
Hur du än gör så kommer ju page_id finns i alla rader som queryn ger. Vill du bara få resultat för EN rad eller, även om det finns flera? Tror inte jag förstår frågan helt korrekt annars.
chrizz är inte uppkopplad   Svara med citatSvara med citat
Oläst 2005-09-29, 22:55 #3
vco-systemss avatar
vco-systems vco-systems är inte uppkopplad
Mycket flitig postare
 
Reg.datum: Dec 2004
Inlägg: 774
vco-systems vco-systems är inte uppkopplad
Mycket flitig postare
vco-systemss avatar
 
Reg.datum: Dec 2004
Inlägg: 774
Nu kan jag få ett resultat som ser ut så här:

Kod:
page_id  subtitle  etc...
24      x
62      y
62      z
62      a
62      b

Det jag vill ha är:

page_id  subtitle  etc...
24      x
62      y
Dvs. varje värde på page_id ska bara finnas 1 gång.
vco-systems är inte uppkopplad   Svara med citatSvara med citat
Oläst 2005-09-29, 23:05 #4
mrnonames avatar
mrnoname mrnoname är inte uppkopplad
Medlem
 
Reg.datum: Sep 2005
Inlägg: 53
mrnoname mrnoname är inte uppkopplad
Medlem
mrnonames avatar
 
Reg.datum: Sep 2005
Inlägg: 53
GROUP BY page_id

Kolla på http://www.w3schools.com/sql/sql_groupby.asp
mrnoname är inte uppkopplad   Svara med citatSvara med citat
Oläst 2005-09-30, 00:16 #5
chrizzs avatar
chrizz chrizz är inte uppkopplad
Medlem
 
Reg.datum: Aug 2004
Inlägg: 296
chrizz chrizz är inte uppkopplad
Medlem
chrizzs avatar
 
Reg.datum: Aug 2004
Inlägg: 296
SELECT DISTINCT nuke_paged_content.page_id AS page_id .... fungerar nog lika bra som GROUP BY, men jag hade kört GROUP BY ändå.

Mao:

Kod:
SELECT DISTINCT nuke_paged_content.page_id AS page_id, nuke_paged_content.subtitle AS subtitle, nuke_paged_content.text AS text, nuke_paged_titles.title AS title, nuke_paged_titles.ingress AS ingress, nuke_paged_titles.topic_id AS topic_id
FROM nuke_paged_content
LEFT JOIN nuke_paged_titles ON ( nuke_paged_content.page_id = nuke_paged_titles.page_id )
WHERE (
nuke_paged_content.subtitle
LIKE "%sökord%" OR nuke_paged_titles.title
LIKE "%sökord%" OR nuke_paged_titles.ingress
LIKE "%sökord%" OR nuke_paged_content.text
LIKE "%sökord%"
)
ger samma som:


Kod:
SELECT nuke_paged_content.page_id AS page_id, nuke_paged_content.subtitle AS subtitle, nuke_paged_content.text AS text, nuke_paged_titles.title AS title, nuke_paged_titles.ingress AS ingress, nuke_paged_titles.topic_id AS topic_id
FROM nuke_paged_content
LEFT JOIN nuke_paged_titles ON ( nuke_paged_content.page_id = nuke_paged_titles.page_id )
WHERE (
nuke_paged_content.subtitle
LIKE "%sökord%" OR nuke_paged_titles.title
LIKE "%sökord%" OR nuke_paged_titles.ingress
LIKE "%sökord%" OR nuke_paged_content.text
LIKE "%sökord%"
GROUP BY page_id
)
säger jag utan att ha provat =)
chrizz är inte uppkopplad   Svara med citatSvara med citat
Oläst 2005-09-30, 07:40 #6
vco-systemss avatar
vco-systems vco-systems är inte uppkopplad
Mycket flitig postare
 
Reg.datum: Dec 2004
Inlägg: 774
vco-systems vco-systems är inte uppkopplad
Mycket flitig postare
vco-systemss avatar
 
Reg.datum: Dec 2004
Inlägg: 774
Citat:
Originally posted by chrizz@Sep 30 2005, 00:16
SELECT DISTINCT nuke_paged_content.page_id AS page_id .... fungerar nog lika bra som GROUP BY, men jag hade kört GROUP BY ändå.

Mao:

Kod:
SELECT DISTINCT nuke_paged_content.page_id AS page_id, nuke_paged_content.subtitle AS subtitle, nuke_paged_content.text AS text, nuke_paged_titles.title AS title, nuke_paged_titles.ingress AS ingress, nuke_paged_titles.topic_id AS topic_id
FROM nuke_paged_content
LEFT JOIN nuke_paged_titles ON ( nuke_paged_content.page_id = nuke_paged_titles.page_id )
WHERE (
nuke_paged_content.subtitle
LIKE "%sökord%" OR nuke_paged_titles.title
LIKE "%sökord%" OR nuke_paged_titles.ingress
LIKE "%sökord%" OR nuke_paged_content.text
LIKE "%sökord%"
)
ger samma som:


Kod:
SELECT nuke_paged_content.page_id AS page_id, nuke_paged_content.subtitle AS subtitle, nuke_paged_content.text AS text, nuke_paged_titles.title AS title, nuke_paged_titles.ingress AS ingress, nuke_paged_titles.topic_id AS topic_id
FROM nuke_paged_content
LEFT JOIN nuke_paged_titles ON ( nuke_paged_content.page_id = nuke_paged_titles.page_id )
WHERE (
nuke_paged_content.subtitle
LIKE "%sökord%" OR nuke_paged_titles.title
LIKE "%sökord%" OR nuke_paged_titles.ingress
LIKE "%sökord%" OR nuke_paged_content.text
LIKE "%sökord%"
GROUP BY page_id
)
säger jag utan att ha provat =)
Citat:

Kod:
SELECT DISTINCT nuke_paged_content.page_id AS page_id, nuke_paged_content.subtitle AS subtitle, nuke_paged_content.text AS text, nuke_paged_titles.title AS title, nuke_paged_titles.ingress AS ingress, nuke_paged_titles.topic_id AS topic_id
FROM nuke_paged_content
LEFT JOIN nuke_paged_titles ON ( nuke_paged_content.page_id = nuke_paged_titles.page_id )
WHERE (
nuke_paged_content.subtitle
LIKE "%sökord%" OR nuke_paged_titles.title
LIKE "%sökord%" OR nuke_paged_titles.ingress
LIKE "%sökord%" OR nuke_paged_content.text
LIKE "%sökord%"
)
Har jag testat tidigare och det fungerar inte.

Citat:

Kod:
SELECT nuke_paged_content.page_id AS page_id, nuke_paged_content.subtitle AS subtitle, nuke_paged_content.text AS text, nuke_paged_titles.title AS title, nuke_paged_titles.ingress AS ingress, nuke_paged_titles.topic_id AS topic_id
FROM nuke_paged_content
LEFT JOIN nuke_paged_titles ON ( nuke_paged_content.page_id = nuke_paged_titles.page_id )
WHERE (
nuke_paged_content.subtitle
LIKE "%sökord%" OR nuke_paged_titles.title
LIKE "%sökord%" OR nuke_paged_titles.ingress
LIKE "%sökord%" OR nuke_paged_content.text
LIKE "%sökord%"
GROUP BY page_id
)
Fungerar utmärkt om man flyttar GROUP BY efter parantesen.

Tack så mycket
vco-systems är inte uppkopplad   Svara med citatSvara med citat
Oläst 2005-09-30, 13:23 #7
chrizzs avatar
chrizz chrizz är inte uppkopplad
Medlem
 
Reg.datum: Aug 2004
Inlägg: 296
chrizz chrizz är inte uppkopplad
Medlem
chrizzs avatar
 
Reg.datum: Aug 2004
Inlägg: 296
Hm, distinct borde ju fungera. Nåja... =)

missade parantesen dock
chrizz är inte uppkopplad   Svara med citatSvara med citat
Svara


Aktiva användare som för närvarande tittar på det här ämnet: 1 (0 medlemmar och 1 gäster)
 

Regler för att posta
Du får inte posta nya ämnen
Du får inte posta svar
Du får inte posta bifogade filer
Du får inte redigera dina inlägg

BB-kod är
Smilies är
[IMG]-kod är
HTML-kod är av

Forumhopp


Alla tider är GMT +2. Klockan är nu 20:51.

Programvara från: vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Svensk översättning av: Anders Pettersson
 
Copyright © 2017