Jump to content
Sign in to follow this  
magician

Join query

Recommended Posts

Hi I've been looking at the tutorial and spoken to a few people regarding a query which requires me to join two tables together and data within a specific data range. The environment I am running this in is SQL Server 2005. The following is the query I have tried to run: select *from individual (this is a table name)where update_timestamp <= 31/12/2008join delegate (this is a table name)as on member.member_ref=delegate.member_Refwhere start_date >= 31/12/2008 but when I run this, I get:Msg 156, Level 15, State 1, Line 4Incorrect syntax near the keyword 'join'. Someone advised me to try the following: select *from individualjoin delegateon member.member_ref=delegate.member_Refwhere start_date >= 31-dec-2008where update_timestamp <= 31-dec-2008 but when I do this, I get:Msg 156, Level 15, State 1, Line 6Incorrect syntax near the keyword 'where'. Can anyone advise me where I'm going wrong? If you require further info, please let me know. Thanks

Share this post


Link to post
Share on other sites

There are a few problems with how your query is written. First, the error message you're getting is because your dates need to be surrounded by single quotes. What are the data types of start_date and update_timestamp? Are they dates, strings, integers....? Second, you are trying to join the table 'individual' with the table 'delegate' on a field from a 'member' table. :huh: Third, your where clause is messed up. It should look something like this:.... WHERE <condition> AND <condition> Fourth, your conditions in the where clause are incorrect. Whenever you are using more than one table in a query, you must use the table name to reference the field:.... WHERE <table_name>.start_date

  • Like 1

Share this post


Link to post
Share on other sites

You're also trying to join on fields in a table called member, but you're not using that table in the join. And in the first query, "as" and "on" don't go next to each other, you use "as" if you want to give the table an alias.

  • Like 1

Share this post


Link to post
Share on other sites
You're also trying to join on fields in a table called member, but you're not using that table in the join.
I believe I mentioned that. :P
Second, you are trying to join the table 'individual' with the table 'delegate' on a field from a 'member' table.

Share this post


Link to post
Share on other sites

Thank you both for this. ShadowMage your advise definitley helped me. I took each section at a time and managed to put it right. Just need to rejig it to give me the fields I want now :huh: Thanks once again.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...