tags:

views:

254

answers:

4

I am trying to display all the names from the table vocabulary where the vids do not match a vid in collapse_menu. How would I do this?

Table vocabulary
    vid     name
    1   Sections
    2   Posts
    6   Forums
    5   Departments
    13  Free Tags
    8   Committees
    9   Training and Workshops
    10  Policies
    12  Projects
    14  Teams

Table collapse_menu
vid
8
5
10
A: 

select name from vocabulary as v, collapse_menu as c where v.vid!=c.vid Edit: Sorry, didn't read the question properly.

Ilya Biryukov
+2  A: 

select name from vocubulary where vid not in (select vid from collapse_menu)

Doug
or use "WHERE NOT EXIST( subselect )"
Nick Franceschina
A: 

SELECT * FROM vocabulary, collapse_menu WHERE vocabulary.vid <> collapse_menu.vid;

davidivins
+3  A: 

I assume that you are asking for the those names in vocabulary, where the vid is not in the collapse_menu table.

In which case

SELECT name
FROM vocabulary
LEFT JOIN collapse_menu ON vocabulary.vid = collapse_menu.vid
WHERE collapse_menu.vid IS NULL
Miles D
Bingo. Some of the other suggestions will work for a simple situation, but this is the technique to remember for complex cases.
SeaDrive