Någon som är bra på sql

Visa första olästa
Ämnesverktyg
Visa huvudforum
Visningsalternativ
Oläst 2005-09-29, 22:58 #1
vco-systemsvco-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?

CODE
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
Oläst 2005-09-29, 23:11 #2
chrizzchrizz ä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
Oläst 2005-09-29, 23:55 #3
vco-systemsvco-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:

CODE
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
Oläst 2005-09-30, 00:05 #4
mrnonamemrnoname ä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
Oläst 2005-09-30, 01:16 #5
chrizzchrizz ä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:

CODE

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:


CODE

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
Oläst 2005-09-30, 08:40 #6
vco-systemsvco-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:

CODE

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:


CODE

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:

CODE

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:

CODE

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 Big Grin
vco-systems är inte uppkopplad
Oläst 2005-09-30, 14:23 #7
chrizzchrizz är inte uppkopplad
Medlem
chrizzs avatar
Reg.datum: Aug 2004
Inlägg: 296
Hm, distinct borde ju fungera. Nåja... =)

missade parantesen dock Wink
chrizz är inte uppkopplad
Aktiva användare som för närvarande tittar på det här ämnet: 0 (0 medlemmar och 0 gäster)