concat and join stuff

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

 



Here some code that works fine, but...
"SELECT b.*, c.publisher,
        CONCAT_WS(' ', first_name, last_name) AS Author
        FROM book AS b
        LEFT JOIN book_publisher as abc ON b.id = abc.bookID
        LEFT JOIN publishers AS c ON abc.publishers_id = c.id
        LEFT JOIN book_author AS ab ON b.id = ab.bookID
        LEFT JOIN author AS a ON ab.authID=a.id
        WHERE LEFT(last_name, 1 ) = '$Auth' ";
This works fine if there is only 1 author for the book; if there are two
they don't show up. I guess I can retrieve the authors from a separate
query, which is not a problem; I just thought it might be better to do
one query as that simplifies the rest of the code.
But doin just one query, would that put a heavier load on the db than
doing several queries?
I would like to modify things to get another Author in there. I had
hoped that it would be possible to do something like
CONCAT_WS(' ', first_name, last_name) WHERE ab.ordinal = 1 AS Author
CONCAT_WS(' ', first_name, last_name) WHERE ab.ordinal = 2 AS Author1
but MySQL doesn't like my creativity.
Or would it be better to join with first_name, last_name, ordinal and
then sort it out from the results...


-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-------------------------------------------------------------
Phil Jourdan --- pj@xxxxxxxxxxxxx
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
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