On 18/04/2009 2:33 PM, flakpit wrote:
> If anyone else has a moment and a concrete example instead of sending me to
> tutorials, feel free to step in here.

If you would take a moment to read the fraction of a screen of a 
tutorial that I pointed you at (and which contains a concrete example), 
instead of repeating what you have already explained you want and is 
screamingly obvious anyway, you might actually *learn* something, and be 
able to find answers for yourself quickly.

> SELECT * FROM pubs                    ; I want ALL columns from the 'pubs'
> table
> 
> WHERE pub_title LIKE '%salem%'  ; Where the title sounds like 'salem'

*sounds* like? The LIKE operator does simple pattern matching ... LIKE 
'%salem%' will match a string containing 'salem' (or 'Salem' or 'SaLem' 
or ...) anywhere, e.g. 'History of Salem, Mass.' or 'Jerusalem'. If you 
want any sort of phonetic matching, you'd have to write a user-defined 
function and use the MATCH operator instead of LIKE.

> The query below retrieves the correct note and publisher for each retrieved
> record in 'pubs' that sounds like 'salem' in the 'pub_title' but also every
> other column in 'notes' and 'publishers' which I don't want.

> I just want the matching notes.note_note for each pubs record and not
> notes.id or notes.idx etc.
> I just want the matching publishers.publisher_name for each pubs record and
> not publishers.id or publishers.idx etc.

> SELECT * FROM pubs

What do you want from the pubs table? All columns
What do you want from the publishers table? The publisher_name column
What do you want from the notes table? the note_note column [are you 
sure? It was note_notes in your previous message]

So just tell it what you want:

SELECT pubs.*, publishers.publisher_name, notes.note_note FROM ...

> INNER JOIN notes
> ON pubs.note_id=notes.note_id
> INNER JOIN publishers
> ON pubs.publisher_id=publishers.publisher_id
> WHERE pub_title LIKE '%salem%'


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to