dbTalk Databases Forums  

Correct SQL Syntax

comp.databases.ms-access comp.databases.ms-access


Discuss Correct SQL Syntax in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
NoodNutt
 
Posts: n/a

Default Correct SQL Syntax - 08-16-2010 , 02:00 AM






Hi all

SQL is without a doubt my downfall, and I'm not gettin any younger, or
smarter in that stable either...

That Said....!!!!!

Can anyone help with the following plz.....

(This works fine)
SELECT [txtMainActor] AS [Actors] FROM tblDVDList
UNION SELECT [txtOtherActor] FROM tblDVDList;

(This on the other-hand, does not)
SELECT [txtMainActor] AS [Actors] FROM tblDVDList, [txtGender] AS [Gender]
FROM tblDVDList
UNION SELECT [txtOtherActor] AS [Actors] FROM tblDVDList, [txtGender] AS
[Gender] FROM tblDVDList;

(I get a SYNTAX error in FROM)

Essentially, I would like to include the gender of each in the UNION if at
all possible...

TIA

Reply With Quote
  #2  
Old   
XPS350
 
Posts: n/a

Default Re: Correct SQL Syntax - 08-16-2010 , 04:28 AM






On 16 aug, 09:00, "NoodNutt" <mcli... (AT) bigpond (DOT) com> wrote:
Quote:
Hi all

SQL is without a doubt my downfall, and I'm not gettin any younger, or
smarter in that stable either...

That Said....!!!!!

Can anyone help with the following plz.....

(This works fine)
SELECT [txtMainActor] AS [Actors] FROM tblDVDList
UNION SELECT [txtOtherActor] FROM tblDVDList;

(This on the other-hand, does not)
SELECT [txtMainActor] AS [Actors] FROM tblDVDList, [txtGender] AS [Gender]
FROM tblDVDList
UNION SELECT [txtOtherActor] AS [Actors] FROM tblDVDList, [txtGender] AS
[Gender] FROM tblDVDList;

(I get a SYNTAX error in FROM)

Essentially, I would like to include the gender of each in the UNION if at
all possible...

TIA
A query to select two fields should look like:
SELECT [txtMainActor] AS [Actors], [txtGender] AS [Gender] FROM
tblDVDList

Groeten,

Peter
http://access.xps350.com

Reply With Quote
  #3  
Old   
Salad
 
Posts: n/a

Default Re: Correct SQL Syntax - 08-16-2010 , 11:38 AM



NoodNutt wrote:
Quote:
Hi all

SQL is without a doubt my downfall, and I'm not gettin any younger, or
smarter in that stable either...

That Said....!!!!!

Can anyone help with the following plz.....

(This works fine)
SELECT [txtMainActor] AS [Actors] FROM tblDVDList
UNION SELECT [txtOtherActor] FROM tblDVDList;

(This on the other-hand, does not)
SELECT [txtMainActor] AS [Actors] FROM tblDVDList, [txtGender] AS [Gender]
FROM tblDVDList
UNION SELECT [txtOtherActor] AS [Actors] FROM tblDVDList, [txtGender] AS
[Gender] FROM tblDVDList;

(I get a SYNTAX error in FROM)

Essentially, I would like to include the gender of each in the UNION if at
all possible...

TIA



Too many Froms. It is Select the fields (columns) first then the From
(source)

SELECT [FldName1] AS Colname1, [FldName2] AS Colname2 FROM TableName;

Check out help for the difference between UNION and UNION ALL. Or
experiment by adding the word All after Union.

IF you have multiple columns and you want to sort the result set it
probably easier to have a line like
Order By 3,2,1
and that will sort by the third, second, and first column. The OrderBy
goes on the last Select in the union query.

Reply With Quote
  #4  
Old   
Phil
 
Posts: n/a

Default Re: Correct SQL Syntax - 08-16-2010 , 05:05 PM



On 16/08/2010 08:00:31, "NoodNutt" wrote:
Quote:
Hi all

SQL is without a doubt my downfall, and I'm not gettin any younger, or
smarter in that stable either...

That Said....!!!!!

Can anyone help with the following plz.....

(This works fine)
SELECT [txtMainActor] AS [Actors] FROM tblDVDList
UNION SELECT [txtOtherActor] FROM tblDVDList;

(This on the other-hand, does not)
SELECT [txtMainActor] AS [Actors] FROM tblDVDList, [txtGender] AS [Gender]
FROM tblDVDList UNION SELECT [txtOtherActor] AS [Actors] FROM tblDVDList,
[txtGender] AS [Gender] FROM tblDVDList;

(I get a SYNTAX error in FROM)

Essentially, I would like to include the gender of each in the UNION if at
all possible...

TIA



Like you, well past it (well you may not be)

If you really want a Union Query, and I don't think you do here, I normally
create 1 standard query using the query design tool for each table (or
query). Add any aliases - like AS Actors, but don't bother with the sort by.
Make sure that there are the same number of output fields and that they have
the same name, are in the same order. If using say 2 tables for your Union
query, copy the SQL version of the second query into the SQL of the first
query, adding the word UNION or UNION ALL just in fronnt of the bit you paste
in. Don't forget to remove the first ";" at the end of the first part of the
SQL. You can then add if you want SORT BY clause. Again ensure there is only
1 ";" at the end

Phil

Reply With Quote
  #5  
Old   
NoodNutt
 
Posts: n/a

Default Re: Correct SQL Syntax - 08-20-2010 , 06:07 AM



Thx heaps to each of you

appreciate your assist.

Cheers

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.