tags:

views:

79

answers:

3
+2  Q: 

Is this SQL valid?

I am still new to implementing joins in my db_design and i am not sure if, at all this SQL is valid.

"SELECT * FROM notes JOIN small_note ON notes_id = '$id' AND authname = '$author' AND bookname = '$book' AND user = '$username'"

A bit easier to read like this:

"SELECT * FROM notes
    JOIN small_note ON notes_id = '$id'
    AND authname = '$author'
    AND bookname = '$book'
    AND user = '$username'";
A: 

I think you need to replace your first AND with WHERE.

Skilldrick
+7  A: 

No it isn't.

You need to specify the join columns for both tables, and you need to make sure you use a correct WHERE clause (which is missing from your query).

This may be more suitable:

SELECT * FROM notes n
JOIN small_note  sn
  ON n.notes_id = sn.notes_id
WHERE notes_id = '$id' 
  AND authname = '$author' 
  AND bookname = '$book' 
  AND user = '$username'
Oded
Also you shouldn't use select * especially when you have a join as it wastes resources.
HLGEM
A: 

No, your $id should be the columnname that holds the reference to the other table. That's not a variable, that's a columnname

Frank Heikens