subqueries in Select = PROBLEM

For school we have to do a project using and MySQL

The teachers told us to use the tutorials that you can find on this website. 

The teacher told u not to use a join (because it could be a problem when you want to insert or update).

I tried to use a subquery like this one (found in one of the tutorials):
SELECT     ProductID, ProductName, SupplierID, CategoryID,
QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued,
(SELECT CategoryName FROM Categories
WHERE Categories.CategoryID = Products.CategoryID) as CategoryName,
(SELECT CompanyName FROM Suppliers
WHERE Suppliers.SupplierID = Products.SupplierID) as SupplierName
FROM         Products

So my select looks something like this:
SELECT firstname, lastname, age, group_id,
(SELECT name
from tblGroup
where = tblPerson.group_id) AS Groupname 
from tblPerson

When using MySQL this gives me the following ERROR:
Generated SELECT statement.
Error in SELECT clause: expression near 'SELECT'.
Error in SELECT clause: expression near 'FROM'.
Missing FROM clause.
Unable to parse query text.

I really hope someone can help me.
4/24/2009 6:15:47 PM 1929 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 19

I guess the samples here are using Sql Server instead of MySql.

Only newer versions of MySql allow subqueries.

Another 2 remarks

Subqueries are SLOW

You should have to use "LIMIT 0,1" at the end of each subquery to return only 1 row per subquery, or nasty stuff will happen.

I really dont know how to show that data without subquery and without joins, so you could try using access or sql express. Access is probably already in your computer, and Sql Express is free.



4/24/2009 11:51:16 PM
Unfortunately I am FORCED to use MySQL.
4/25/2009 7:26:31 AM