Page 1 of 1

sql query help

Posted: Tue Apr 06, 2004 5:33 pm
by forgodsake8
Hi,
I'm trying to write a query that when a user enters a search term in a text box such as Computing, it will then check whether there are any adverts available with Computing in their title.

The tables are:

advert2
(advert_id, username, mod_book_id, asking_price, condition, description, date_added)

ts_module_books
(id, module_code, essential_useful, author, book_title, publisher, pub_year)

the query im using is:

"select * from ts_module_books inner join advert2 on advert2.mod_book_id = ts_module_books.id where ts_module_books.book_title LIKE '%$search%'"

However, what i want outputting to the page is

book_title, author and publisher from ts_module_books,
and also user from the advert2 table.

Is this possible? And if so, how do i do this?

Thanks.

Lou

Posted: Tue Apr 06, 2004 5:49 pm
by tim
I may be off base

but just replace the * with the desired fields

SELECT books,item2,item3 FROM table_name etc etc WHERE blah=blah

Posted: Tue Apr 06, 2004 6:29 pm
by forgodsake8
The problem is that I want to return ALL the fields from ts_module_books,
where the $search term is in ts_module_books.book_title and also appears in advert2.
As well as this, I want it to return the username from the advert2 table.

If this makes sense!

any ideas?

Lou

Posted: Tue Apr 06, 2004 7:55 pm
by andre_c
like this?

Code: Select all

SELECT ts_module_books.*, advert2.username FROM ....