Unix Technical Forum

Another SQL syntax problem

This is a discussion on Another SQL syntax problem within the MySQL forums, part of the Database Server Software category; --> OK, another newbie with a dumb question. Why doesn't my query work? SELECT pmainT.product + '.75' + woodtype.short AS ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:36 AM
Matthew256
 
Posts: n/a
Default Another SQL syntax problem

OK, another newbie with a dumb question. Why doesn't my query work?

SELECT pmainT.product + '.75' + woodtype.short AS SKU, psubT.ID + .75
AS id, ROUND(psubT.price * 1.65, 2) AS price,
psubT.pmain_ID + .75 AS Expr1, psubT.woodtype_ID, psubT.weight * .75 AS
weight, psubT.oldweight, psubT.turning
FROM woodtype INNER JOIN
pmainT INNER JOIN
psubT ON pmainT.ID = psubT.pmain_ID ON woodtype.ID = psubT.woodtype_ID
WHERE (pmainT.milling = 1) AND (pmainT.twosquares = 0)

MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'ON woodtype . ID = psubT . woodtype_ID WHERE ( pmainT . milling
= 1 ) AND ( pma' at line 1

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:36 AM
Captain Paralytic
 
Posts: n/a
Default Re: Another SQL syntax problem


Matthew256 wrote:
> OK, another newbie with a dumb question. Why doesn't my query work?
>
> SELECT pmainT.product + '.75' + woodtype.short AS SKU, psubT.ID + .75
> AS id, ROUND(psubT.price * 1.65, 2) AS price,
> psubT.pmain_ID + .75 AS Expr1, psubT.woodtype_ID, psubT.weight * .75 AS
> weight, psubT.oldweight, psubT.turning
> FROM woodtype INNER JOIN
> pmainT INNER JOIN
> psubT ON pmainT.ID = psubT.pmain_ID ON woodtype.ID = psubT.woodtype_ID
> WHERE (pmainT.milling = 1) AND (pmainT.twosquares = 0)
>
> MySQL said:
> #1064 - You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near 'ON woodtype . ID = psubT . woodtype_ID WHERE ( pmainT . milling
> = 1 ) AND ( pma' at line 1

Because you have your JOINs and ONs all mixed up.
Try this (tidied up a bit):

SELECT
pmainT.product + '.75' + woodtype.short AS SKU,
psubT.ID + .75 AS id,
ROUND(psubT.price * 1.65, 2) AS price,
psubT.pmain_ID + .75 AS Expr1,
psubT.woodtype_ID,
psubT.weight * .75 AS weight,
psubT.oldweight,
psubT.turning
FROM woodtype
INNER JOIN psubT ON woodtype.ID = psubT.woodtype_ID
INNER JOIN pmainT ON pmainT.ID = psubT.pmain_ID
WHERE (pmainT.milling = 1) AND (pmainT.twosquares = 0)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:36 AM
Matthew256
 
Posts: n/a
Default Re: Another SQL syntax problem


Captain Paralytic wrote:
> Matthew256 wrote:
> > OK, another newbie with a dumb question. Why doesn't my query work?
> >
> > SELECT pmainT.product + '.75' + woodtype.short AS SKU, psubT.ID + .75
> > AS id, ROUND(psubT.price * 1.65, 2) AS price,
> > psubT.pmain_ID + .75 AS Expr1, psubT.woodtype_ID, psubT.weight * .75 AS
> > weight, psubT.oldweight, psubT.turning
> > FROM woodtype INNER JOIN
> > pmainT INNER JOIN
> > psubT ON pmainT.ID = psubT.pmain_ID ON woodtype.ID = psubT.woodtype_ID
> > WHERE (pmainT.milling = 1) AND (pmainT.twosquares = 0)
> >
> > MySQL said:
> > #1064 - You have an error in your SQL syntax; check the manual that
> > corresponds to your MySQL server version for the right syntax to use
> > near 'ON woodtype . ID = psubT . woodtype_ID WHERE ( pmainT . milling
> > = 1 ) AND ( pma' at line 1

> Because you have your JOINs and ONs all mixed up.
> Try this (tidied up a bit):
>
> SELECT
> pmainT.product + '.75' + woodtype.short AS SKU,
> psubT.ID + .75 AS id,
> ROUND(psubT.price * 1.65, 2) AS price,
> psubT.pmain_ID + .75 AS Expr1,
> psubT.woodtype_ID,
> psubT.weight * .75 AS weight,
> psubT.oldweight,
> psubT.turning
> FROM woodtype
> INNER JOIN psubT ON woodtype.ID = psubT.woodtype_ID
> INNER JOIN pmainT ON pmainT.ID = psubT.pmain_ID
> WHERE (pmainT.milling = 1) AND (pmainT.twosquares = 0)


That did it.
Thanks for your help!

Matthew

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:36 AM
Matthew256
 
Posts: n/a
Default Re: Another SQL syntax problem


Matthew256 wrote:
> Captain Paralytic wrote:
> > Matthew256 wrote:
> > > OK, another newbie with a dumb question. Why doesn't my query work?
> > >
> > > SELECT pmainT.product + '.75' + woodtype.short AS SKU, psubT.ID + .75
> > > AS id, ROUND(psubT.price * 1.65, 2) AS price,
> > > psubT.pmain_ID + .75 AS Expr1, psubT.woodtype_ID, psubT.weight * .75 AS
> > > weight, psubT.oldweight, psubT.turning
> > > FROM woodtype INNER JOIN
> > > pmainT INNER JOIN
> > > psubT ON pmainT.ID = psubT.pmain_ID ON woodtype.ID = psubT.woodtype_ID
> > > WHERE (pmainT.milling = 1) AND (pmainT.twosquares = 0)
> > >
> > > MySQL said:
> > > #1064 - You have an error in your SQL syntax; check the manual that
> > > corresponds to your MySQL server version for the right syntax to use
> > > near 'ON woodtype . ID = psubT . woodtype_ID WHERE ( pmainT . milling
> > > = 1 ) AND ( pma' at line 1

> > Because you have your JOINs and ONs all mixed up.
> > Try this (tidied up a bit):
> >
> > SELECT
> > pmainT.product + '.75' + woodtype.short AS SKU,
> > psubT.ID + .75 AS id,
> > ROUND(psubT.price * 1.65, 2) AS price,
> > psubT.pmain_ID + .75 AS Expr1,
> > psubT.woodtype_ID,
> > psubT.weight * .75 AS weight,
> > psubT.oldweight,
> > psubT.turning
> > FROM woodtype
> > INNER JOIN psubT ON woodtype.ID = psubT.woodtype_ID
> > INNER JOIN pmainT ON pmainT.ID = psubT.pmain_ID
> > WHERE (pmainT.milling = 1) AND (pmainT.twosquares = 0)

>
> That did it.
> Thanks for your help!
>
> Matthew


Here's another query question.
I know this looks crazy, but it's a simplified version of my query. I
need to do about five UNION ALLs in the subquery.

CREATE VIEW pmain AS
SELECT original,
ID,
type_ID,
dimensions,
leg_name,
product,
leg_description,
milling,
oversize,
trackproduction,
active,
height,
SORT,
customize
FROM
(SELECT 1 AS original,
ID,
type_ID,
dimensions,
leg_name,
product,
leg_description,
milling,
oversize,
trackproduction,
active,
height,
SORT,
customize
FROM pmainT
WHERE (active = 1)
) AS a
WHERE (active = 1)

MySQL said:
#1349 - View's SELECT contains a subquery in the FROM clause

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 09:36 AM
Matthew256
 
Posts: n/a
Default Re: Another SQL syntax problem


Matthew256 wrote:
> Matthew256 wrote:
> > Captain Paralytic wrote:
> > > Matthew256 wrote:
> > > > OK, another newbie with a dumb question. Why doesn't my query work?
> > > >
> > > > SELECT pmainT.product + '.75' + woodtype.short AS SKU, psubT.ID + .75
> > > > AS id, ROUND(psubT.price * 1.65, 2) AS price,
> > > > psubT.pmain_ID + .75 AS Expr1, psubT.woodtype_ID, psubT.weight * .75 AS
> > > > weight, psubT.oldweight, psubT.turning
> > > > FROM woodtype INNER JOIN
> > > > pmainT INNER JOIN
> > > > psubT ON pmainT.ID = psubT.pmain_ID ON woodtype.ID = psubT.woodtype_ID
> > > > WHERE (pmainT.milling = 1) AND (pmainT.twosquares = 0)
> > > >
> > > > MySQL said:
> > > > #1064 - You have an error in your SQL syntax; check the manual that
> > > > corresponds to your MySQL server version for the right syntax to use
> > > > near 'ON woodtype . ID = psubT . woodtype_ID WHERE ( pmainT . milling
> > > > = 1 ) AND ( pma' at line 1
> > > Because you have your JOINs and ONs all mixed up.
> > > Try this (tidied up a bit):
> > >
> > > SELECT
> > > pmainT.product + '.75' + woodtype.short AS SKU,
> > > psubT.ID + .75 AS id,
> > > ROUND(psubT.price * 1.65, 2) AS price,
> > > psubT.pmain_ID + .75 AS Expr1,
> > > psubT.woodtype_ID,
> > > psubT.weight * .75 AS weight,
> > > psubT.oldweight,
> > > psubT.turning
> > > FROM woodtype
> > > INNER JOIN psubT ON woodtype.ID = psubT.woodtype_ID
> > > INNER JOIN pmainT ON pmainT.ID = psubT.pmain_ID
> > > WHERE (pmainT.milling = 1) AND (pmainT.twosquares = 0)

> >
> > That did it.
> > Thanks for your help!
> >
> > Matthew

>
> Here's another query question.
> I know this looks crazy, but it's a simplified version of my query. I
> need to do about five UNION ALLs in the subquery.
>
> CREATE VIEW pmain AS
> SELECT original,
> ID,
> type_ID,
> dimensions,
> leg_name,
> product,
> leg_description,
> milling,
> oversize,
> trackproduction,
> active,
> height,
> SORT,
> customize
> FROM
> (SELECT 1 AS original,
> ID,
> type_ID,
> dimensions,
> leg_name,
> product,
> leg_description,
> milling,
> oversize,
> trackproduction,
> active,
> height,
> SORT,
> customize
> FROM pmainT
> WHERE (active = 1)
> ) AS a
> WHERE (active = 1)
>
> MySQL said:
> #1349 - View's SELECT contains a subquery in the FROM clause


The really strange part is, if I take off the first line it works fine.
> CREATE VIEW pmain AS


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:46 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com