Forum Moderators: coopster

Message Too Old, No Replies

simple mysql query in PHP

         

dtest

9:01 pm on Mar 4, 2008 (gmt 0)

10+ Year Member



I have 2 mysql tables:

ID, TITLE, AMOUNT
ID, STATUS, PRICE

(edit: no gifs were allowed, so I will try to paste the text...)

table1:

ID,TITLE,AMOUNT
100,the cat in the hat,40
101,great expectations,29
102,the man who knew too little,33
103,a cry for help,34
104,holding the smoking gun,31
105,the next karate kid,60
106,raising cain,23

table2:

ID,STATUS,PRICE
100,0,19.99
101,1,18.95
102,1,20.95
103,1,19.99
104,1,19.99
105,1,20.95
106,0,19.99

I would like to select all from table1 where TITLE contains 'the' and where STATUS (located in table2) = 1

What would the exact query be to achieve this?

The result of the query should be 3 records: ID 102, 104 and 105

[edited by: jatar_k at 9:07 pm (utc) on Mar. 4, 2008]

[edited by: dtest at 9:24 pm (utc) on Mar. 4, 2008]

jatar_k

9:11 pm on Mar 4, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't actually see a column named NAME so I assume you mean TITLE

why the need for two tables? Why not just have ID, TITLE, AMOUNT, STATUS, PRICE in one table. Unless you plan on having more than one status attributed to a single book (guessing they are books).

your query could then just be

select * from tablename where TITLE like '%the%' and STATUS = 0;

otherwise you have to join the tables which adds tons of overhead.

dtest

9:29 pm on Mar 4, 2008 (gmt 0)

10+ Year Member



yes, sorry, I meant TITLE instead of NAME

well the reason I "need" 2 tables is because I am working with a software package that uses multiple tables for the data on these books

these tables I included are just an example, the real ones in the software package are a lot bigger and complex, I just wrote these 2 tables to create a simple example

please tell me more about joining tables