sql query help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
forgodsake8
Forum Newbie
Posts: 9
Joined: Fri Feb 27, 2004 8:30 pm

sql query help

Post 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
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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
forgodsake8
Forum Newbie
Posts: 9
Joined: Fri Feb 27, 2004 8:30 pm

Post 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
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

like this?

Code: Select all

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