Re: formulate nested select

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim Lucas wrote:
Chris wrote:
PJ wrote:
I cannot find anything on google or the manuals/tutorials that gives
some kin of clear explanation of how to so nested selects with where or
whatever.
I have three tables: books, authors and book-authors.
I need to retrieve only those books whose author's names begin with A.
I have tried several maniipulations of where and select with select
subqueries and I cannot get results from the queries.
For example
"SELECT * FROM book b, book_authors c (SELECT id FROM author WHERE
LEFT(author.last_name = $Auth )) as a WHERE a.id = c.authID && b.id =
c.bookID ....<snip>

Not really a php question :P

You don't need a subquery for this. You can join all of the tables together and just use the where clause to cut down your results, but I'll give an example of both.

select *
from
  books b inner join book_authors c on (b.id=c.bookId)
  inner join authors a on (a.id=c.authorId)
where
  left(a.last_name = 'A');

correct me if I'm wrong, but did you use the left() function in-correctly?

Probably, I didn't look at the doco - I (stupidly I know) assumed it was correct in the original example.

Thanks for the correction.

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux