tags:

views:

210

answers:

6
SELECT * FROM table1, table2
WHERE table1.user_id = table2.id
AND table1.content = news
AND table1.content_id = 1

that wont work. cant u have two "AND" in a sql statement??

//Tomek

+11  A: 

you probably want to quote 'news' as a string... You also probably want to use an inner join instead (much more efficient)

SELECT * FROM table1
INNER JOIN table2 ON table1.user_id = table2.id 
WHERE table1.content = 'news' 
AND table1.content_id = 1
+4  A: 

news is what? Some sort of parameter? Value of the field? A word which should occur in the field? Most likely your syntax is wrong, see W3Schools WHERE and W3Schools AND/OR operators pages for more information.

Esko
A: 
  • What do table1 and table2 look like? Can you paste a create script?
  • I would STRONGLY recommend to use the proper JOIN syntax:

    select * from table1 inner join table2 on table1.user_id = table2.id ......

  • what datatypes is "table1.content" ?

You can most definitely have a lot more than just 2 AND statements in a SQL query - any database that really support any of the SQL-xx standards will support this...

Marc

marc_s
+3  A: 

let me rewrite that for you with a JOIN statement since it is not 1995 anymore, you also need quotes around news

SELECT * FROM table1 t1
inner join table2 t2 on t1.user_id = t2.id
AND t1.content = 'news'
AND t1.content_id = 1
SQLMenace
A: 

I liked cmartin's response. Also, you can use more than one AND, if needed.

Epitaph
+1  A: 
HLGEM