<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: help on SQL </title>
	<link>http://ask.metafilter.com/41258/help-on-SQL/</link>
	<description>Comments on Ask MetaFilter post help on SQL</description>
	<pubDate>Fri, 30 Jun 2006 12:58:22 -0800</pubDate>
	<lastBuildDate>Fri, 30 Jun 2006 12:58:22 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: help on SQL </title>
		<link>http://ask.metafilter.com/41258/help-on-SQL</link>	
		<description>Need some help with combining SQL queries.  New to SQL - some programming back ground. &lt;br /&gt;&lt;br /&gt; I have two very simple SQL statements, I am VERY new to SQL so I am trying to &quot;learn as I go.&quot;&lt;br&gt;
I have two queries I would like to combine to save time:&lt;br&gt;
&lt;br&gt;
select rtf_seq from enc_documentation&lt;br&gt;
where enc_seq = &lt;br&gt;
&lt;br&gt;
select * from text_document&lt;br&gt;
where text_document_seq = &lt;br&gt;
for update&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
As a note:&lt;br&gt;
text_documentation seq = rtf_seq (just different names on different tables).&lt;br&gt;
&lt;br&gt;
Thank you</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2006:site.41258</guid>
		<pubDate>Fri, 30 Jun 2006 12:47:36 -0800</pubDate>
		<dc:creator>lutzla23</dc:creator>
		
			<category>sql</category>
		
	</item> <item>
		<title>By: utsutsu</title>
		<link>http://ask.metafilter.com/41258/help-on-SQL#635295</link>	
		<description>ok so something like, &lt;br&gt;
&lt;br&gt;
select * from enc_documentation, text_document &lt;br&gt;
where text_documentation_seq = rtf_seq AND enc_seq = whatever_value_you_are_querying_for&lt;br&gt;
&lt;br&gt;
This &quot;joins&quot; the two tables based on text_documentation_seq = rtf_seq. It will return all fields from both tables, for all rows where these two fields are equal AND enc_seq equals the desired value. &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Note that it is good practice to keep the same field name for fields that exist in multiple tables.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.41258-635295</guid>
		<pubDate>Fri, 30 Jun 2006 12:58:22 -0800</pubDate>
		<dc:creator>utsutsu</dc:creator>
	</item><item>
		<title>By: lutzla23</title>
		<link>http://ask.metafilter.com/41258/help-on-SQL#635301</link>	
		<description>Fabulous,&lt;br&gt;
thank you!&lt;br&gt;
&lt;br&gt;
Do you recommend a good tutorial/book for sql, most of what i&apos;ll be doing is querie based and should not be very complex.&lt;br&gt;
&lt;br&gt;
thank you again utsutsu</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.41258-635301</guid>
		<pubDate>Fri, 30 Jun 2006 13:06:03 -0800</pubDate>
		<dc:creator>lutzla23</dc:creator>
	</item><item>
		<title>By: felix</title>
		<link>http://ask.metafilter.com/41258/help-on-SQL#635305</link>	
		<description>it looks like your query didn&apos;t make it all the way through.  Additionally, specifying the database platform would be a good idea, as each has weird issues and tricks.  Finally, &apos;combine&apos; can have several different meanings in database terms.&lt;br&gt;
&lt;br&gt;
However, let&apos;s say that you meant that you want to get all records from the two tables &quot;text_document&quot; and &quot;enc_documentation&quot; where they both share a sequence number (&quot;rtf_seq&quot; or &quot;seq&quot;), and to ignore all the records which have a sequence number that is not shared in the other table.  This operation is called an &quot;inner join&quot; in database terminology and is the easiest and most common way of combining data in sql.&lt;br&gt;
&lt;br&gt;
First, you should fix the tables so that their sequence identifiers are the same; &quot;seq&quot; being equivalent to &quot;rtf_seq&quot; is just nasty and dangerous.  Nevertheless, continuing as if that wasn&apos;t fixed:&lt;br&gt;
&lt;br&gt;
select t.*&lt;br&gt;
from text_document t, enc_documentation e&lt;br&gt;
where t.seq = r.rtf_seq&lt;br&gt;
for update&lt;br&gt;
&lt;br&gt;
note that the &apos;for update&apos; syntax will either work or not depending on what platform and db you&apos;re on.&lt;br&gt;
&lt;br&gt;
There are other ways to combine the data; there are &apos;outer joins&apos;, with which you can say that you want all the rows from one table, and any matching rows if available from &lt;br&gt;
the other table, and so forth.  &lt;br&gt;
&lt;br&gt;
You might profitably invest some time in typing &quot;SQL introduction&quot; into google.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.41258-635305</guid>
		<pubDate>Fri, 30 Jun 2006 13:09:31 -0800</pubDate>
		<dc:creator>felix</dc:creator>
	</item><item>
		<title>By: Mr. Six</title>
		<link>http://ask.metafilter.com/41258/help-on-SQL#635306</link>	
		<description>&lt;a href=&quot;http://sol.gfxile.net/galaxql.html&quot;&gt;Galaxql&lt;/a&gt; is an excellent and engaging SQL tutorial.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.41258-635306</guid>
		<pubDate>Fri, 30 Jun 2006 13:10:10 -0800</pubDate>
		<dc:creator>Mr. Six</dc:creator>
	</item><item>
		<title>By: ijoshua</title>
		<link>http://ask.metafilter.com/41258/help-on-SQL#635312</link>	
		<description>This is for  the case then there is a one-to-one correspondence from enc_documentation -&amp;gt; text_document:&lt;br&gt;
&lt;br&gt;
&lt;code&gt;&lt;br&gt;
SELECT *&lt;br&gt;
FROM enc_documentation&lt;br&gt;
INNER JOIN text_document ON text_document.text_document_seq = enc_documentation.rtf_seq&lt;br&gt;
WHERE enc_documentation.enc_seq = ?&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
For other relationship types, you would need to use a different JOIN.  Can you give more information on the exact relationship between the two tables?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.41258-635312</guid>
		<pubDate>Fri, 30 Jun 2006 13:16:17 -0800</pubDate>
		<dc:creator>ijoshua</dc:creator>
	</item><item>
		<title>By: lutzla23</title>
		<link>http://ask.metafilter.com/41258/help-on-SQL#635316</link>	
		<description>Thanks felix, actually all of the query made it through.&lt;br&gt;
And the two querys work fine independantly. &lt;br&gt;
&lt;br&gt;
I understand what you are saying for the database and different seq names and I agree, but I didn&apos;t create the database.&lt;br&gt;
&lt;br&gt;
The query sent through by utsutsu worked great.&lt;br&gt;
&lt;br&gt;
I don&apos;t quite understand your query as far as where do I input the enc_seq to drive the query?&lt;br&gt;
&lt;br&gt;
Like I said I am new to this.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.41258-635316</guid>
		<pubDate>Fri, 30 Jun 2006 13:18:49 -0800</pubDate>
		<dc:creator>lutzla23</dc:creator>
	</item><item>
		<title>By: felix</title>
		<link>http://ask.metafilter.com/41258/help-on-SQL#635330</link>	
		<description>select rtf_seq from enc_documentation&lt;br&gt;
where enc_seq =&lt;br&gt;
&lt;br&gt;
is, by itself, not a valid query.  SQL needs you to fill in the thing after the equals sign.  It&apos;s possible that your tool/development environment/database thing/whatever is finding a way to fill that out for you, but it&apos;s unclear how it might.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.41258-635330</guid>
		<pubDate>Fri, 30 Jun 2006 13:32:37 -0800</pubDate>
		<dc:creator>felix</dc:creator>
	</item><item>
		<title>By: elderling</title>
		<link>http://ask.metafilter.com/41258/help-on-SQL#635348</link>	
		<description>I find the following books invaluable:&lt;br&gt;
&lt;br&gt;
BOOK: &lt;a href=&quot;http://safari.oreilly.com/0596007272&quot;&gt;Learning SQL&lt;/a&gt;&lt;br&gt;
by Alan Beaulieu&lt;br&gt;
Publisher: O&apos;Reilly&lt;br&gt;
Pub Date: August 2005&lt;br&gt;
ISBN: 0-596-00727-2&lt;br&gt;
Pages: 306&lt;br&gt;
&lt;br&gt;
This one&apos;s a great introduction.&lt;br&gt;
&lt;br&gt;
BOOK: &lt;a href=&quot;http://safari.oreilly.com/0596009763&quot;&gt;SQL Cookbook&lt;/a&gt;&lt;br&gt;
by Anthony Molinaro&lt;br&gt;
Publisher: O&apos;Reilly&lt;br&gt;
Pub Date: December 2005&lt;br&gt;
ISBN: 0-596-00976-3&lt;br&gt;
Pages: 628&lt;br&gt;
&lt;br&gt;
This one&apos;s great for study and solving real-world problems.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.41258-635348</guid>
		<pubDate>Fri, 30 Jun 2006 13:44:08 -0800</pubDate>
		<dc:creator>elderling</dc:creator>
	</item><item>
		<title>By: AmbroseChapel</title>
		<link>http://ask.metafilter.com/41258/help-on-SQL#635447</link>	
		<description>The W3Schools SQL tutorials are really good because they actually have a database that you query online and see the results live. See &lt;a href=&quot;http://www.w3schools.com/sql/sql_tryit.asp&quot;&gt;this example&lt;/a&gt; for instance.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.41258-635447</guid>
		<pubDate>Fri, 30 Jun 2006 16:08:52 -0800</pubDate>
		<dc:creator>AmbroseChapel</dc:creator>
	</item>
	</channel>
</rss>
