Jump to content
  • Advertisement
Sign in to follow this  

[SQL] Help w/ JOIN command

This topic is 4723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am supposed to retrieve data off different tables w/ different queries and make them into one large report. Problem is, I've never used JOIN before, and my 'boss' said that's the command that should help you do all the querying in one foul swoop. So I read into it on the W3Cschools site and it said it's a function to join queries into a large query. Well now, I tried giving it a show for a while, and I can't seem to figure it out. Maybe someone can help me straighten out my query. I need to grab 2 fields from the table LatestLSAP, [id] and [expiredate]. So I do my join like so:
join
{
	select distinct [id], [expiredate]
	FROM LatestLSAP
	WHERE usercompanyid = c2.usercompanyid
}
C2 was some other object (or w/e it's called) from the rest of the query before this. It's the table I need to get the info from, so I don't think it's that. I also see there's some 'on' command you put after the JOIN's closing brace to specify something. I'm really lost, please help. :<

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I've never seen such a thing before. What language are you trying to use?

In case it's of any help to you, here is how I'd do that in SQL:


SELECT DISTINCT LatestLSAP.id, LatestLSAP.expiredate FROM LatestLSAP JOIN c2 ON LatestLSAP.usercompanyid = c2.usercompanyid



This is just an example because I don't know exactly what you're trying to do. The join will probably require some tweaking to get what you want (you'll likely have to specify whether it's a left, right, inner, ... join). Note that the exact syntax could vary slightly from one SQL engine to another.


Hope this helps.

Share this post


Link to post
Share on other sites
Ya this is MS SQL, but it seems to follow most of SQL pretty sharply. I think using JOIN by default is an INNER JOIN in MS SQL. I just want to pull 2 columns on that LSAP table where the usercompanyid is equal to the one being called on another JOIN.

Share this post


Link to post
Share on other sites
I think you need to better explain what you want to do (don't try phrase in how you are trying to do it, phrase it as what you have in terms of data and what result you want. Do not use the word join). You may be looking for a join (in which case your syntax is not even close), or you may be looking for a union. We'll only know if we understand what you actually want to do.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!