[thelist] SQL question
Ken Schaefer
Ken at adOpenStatic.com
Mon May 1 19:25:05 CDT 2006
Try these (not tested!)
SELECT
a.Path
FROM
Categories AS a
WHERE EXISTS
(
SELECT
NULL
FROM
Categories AS b
WHERE
b.Category = 'Cheese'
AND
b.Path = a.Path
)
AND
a.Category = 'Stilton'
--- or this one ----
SELECT
a.path
FROM
Categories AS a
INNER JOIN
Categories AS b
ON
a.Path = b.Path
WHERE
a.Category = "Cheese"
AND
b.Category = "Stilton"
HTH
Cheers
Ken
: -----Original Message-----
: From: thelist-bounces at lists.evolt.org [mailto:thelist-
: bounces at lists.evolt.org] On Behalf Of Kevin Sedgley
: Sent: Tuesday, 2 May 2006 1:20 AM
: To: thelist at lists.evolt.org
: Subject: [thelist] SQL question
:
: Hello list,
:
: This is probably blindingly simple but my brain isn't working on this
: lovely
: sunny bank holiday.
:
: I have a table with the following data:
:
: -----------------------
: | category | path |
: -----------------------
: | cheese | /cheese |
: | cheddar | /cheddar |
: | stilton | /stilton |
: | cheese | /cheddar |
: | cheese | /stilton |
: -----------------------
:
: (both category and path are primary keys)
:
: If I wanted to search for a path where category is "stilton" and for
: the
: same path the category "cheese" (so the result would be /stilton) is
: this
: possible just using SQL? I'm using MySQL so I can use proprietary
: commands
: if need be.
:
: I was thinking something like SELECT * FROM categories, categories
: WHERE
: category = "cheese" AND category = "stilton" (so combining the same
: table
: twice) but this isn't allowed.
:
: Thanks for your time,
More information about the thelist
mailing list