GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Oct-2007, 22:36
checkerboard checkerboard is offline
New Member
 
Join Date: May 2007
Posts: 1
checkerboard is on a distinguished road

sql help


Hi guys,
I am having some problems in writing a sql query for search.My case is as
given below
I have two tables books(having attributes like titles,subtitles etc)
and authors(having attributes first name and last name).They have a
many to many relationship between them and related by books_authors
table.
Now I want to write a sql query such that any string provided by the user that matches
the author fname,lname or books title subtitle then it must show the
result.
How can I achieve this using joins or any other way
Seeking for help
  #2  
Old 02-Nov-2007, 20:50
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: sql help


The resulting query would really depend on how well the tables are put together [normalized].

Can you post more info. [the specific fields] contained in each table, and how they are related?

Also have a look at this short 'normalization' (a simplified "Mike's Bookstore") example . It might also give some ideas.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 10-Nov-2007, 21:18
MonkOfox MonkOfox is offline
New Member
 
Join Date: Nov 2007
Posts: 21
MonkOfox is on a distinguished road

Re: sql help


well you have two different tables, and you want to determine if something someone inputs is contained in one or all of three different fields, two which are from authors, and 1 which is from books.

we'll set up your from statement first.



Code:
from books e, authors b // the first thing to do is realize what you want to get, but more important // to realize where that data is coming from.

then you can set up your select statement.

Code:
select e.subtitle,b.fname,b.lname // so now you have what you want to select and from what table(s).

and then your where clause.

Code:
'where e.subtitle = '.$userInput.' OR b.fname = '.$userInput2.' OR b.lname = '.$userInput3.';'; //may have some of my string literals off, hope not. //but this is the jist of the idea. and if your not using php //you can just apply this same concept to java/c++ etc..

i think the 'books e' syntax is considered an "alias" so if you have two attributes named the same you can distinguish them by making multiple 'instances' of the two or more different tables.

I hope this is what you were looking for, if not please email me at
twotwohappy@hotmail.com

I can try to help you further.

p.s

dont forget to close your whole sql statement with the ;

for example:

select
from
where;

basically

MonkO

the 'where clause' is also assuming that your inputs correspond with the three different attributes specifically.

OR's and AND's are long and drawn out, but usually the easiest way to get what you want.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unlimited Domain Hosting – Reselling with Windows 2003| Linux | CF MX | SQL | ASP.NET JodoHost Web Hosting Advertisements & Offers 0 04-Apr-2007 23:08
getting an error while compiling and running using different IDE. jaro C Programming Language 0 25-Aug-2006 10:14
functions seems not to exit from a certain code block jaro C Programming Language 3 22-Mar-2006 00:08
Microsoft SQL Server :: SQL Server message 241, state 1, severity 16 lyuboe MySQL / PHP Forum 0 11-May-2005 05:31
DiscountASP.NET Launches SQL Reporting Services dasp Web Hosting Advertisements & Offers 0 19-Oct-2004 18:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:25.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.