473,225 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

Subquery Help

Here's my setup. I have three tables I am working with: product,
attribute, and vendor. An attribute is a variation of a product. For
instance, if I have a widget, a red widget would be one attribute, a green
widget would be a second, a blue one would be a third, and so on. A product
is identified by a nine digit SKU, and an attribute is identified by an 11
digit SKU. The attribute SKU is the product SKU plus a two digit
identifier. for instance, if the product SKU is 123456789, the first
attribute would be 12345678901, the second would be 12345678902, and so on.

The vendor table contains all vendors, and they can be either a manufacturer
or a distributor. Each vendor is identified by a vendor_id value. Each
product has a manufacturer and a distributor, idientified by the
product.manufacturer_id and product.distributor_id fields, where those two
fields contain a vendor_id.

I need to generate a report that lists all attributes for a given vendor
(the vendor is chosen from a drop down list in an HTML form). I am trying
to write a query that will get this data instead of having to do multiple
queries. I was going to use a subquery, but the version of MySQL on the
ISP's server is 4.0.22, so subqueries aren't supported (only after 4.1
according to the MySQL site).

So it looks like I need to go through two steps to get the data I need:
1) Get all records from the product table that have a certain
manufacturer_id value
2) For each product, get all corresponding rows in the attribute table.

With 4.0.22, is it possible to get this data in one query? Or do I need to
do something like:
1) Run first query to get list of products with appropriate manufacturer_id
2) Put each value in an array
3) For each product_sku, get the corresponding rows from the attribute table

Or is there a third option I should consider?

Thanks.

Steve
Jul 17 '05 #1
2 1334
On 2005-05-03, Steve Edwards <ra***********@hotmail.com> wrote:
I need to generate a report that lists all attributes for a given vendor
(the vendor is chosen from a drop down list in an HTML form). I am trying
to write a query that will get this data instead of having to do multiple
queries. I was going to use a subquery, but the version of MySQL on the
ISP's server is 4.0.22, so subqueries aren't supported (only after 4.1
according to the MySQL site).
Could you give us an example of that query then?
Or is there a third option I should consider?


Read a SQL manual, and pay special attention to the JOIN clause.

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #2
Steve Edwards wrote:
widget would be a second, a blue one would be a third, and so on. A
product is identified by a nine digit SKU, and an attribute is identified
by an 11
digit SKU. The attribute SKU is the product SKU plus a two digit
identifier. for instance, if the product SKU is 123456789, the first
attribute would be 12345678901, the second would be 12345678902, and so
on.
<snip> Or is there a third option I should consider?


Normalize your data - the composite key in the attribute relation breaks
first normal form.

C.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: leegold2 | last post by:
I tried what's below, seemed OK, so I replaced an "IN" for the "=" in the subquery below because of the subquery's error message. I thought w/"IN" I'd get three (3) records returned as expected....
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
7
by: K. Crothers | last post by:
I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of...
5
by: Rod | last post by:
I have a client site where the code below has been working happily for at least four months. The site is using SQL Server 7. The code is ASP.NET Last week an error appeared related to the...
6
by: phillip.s.powell | last post by:
update student s set school_year_id = (select distinct s.id from school_year s, interns i where lower(s.school_year_name) = lower(i.enrollment_year)and s.unique_key = i.unique_key group by s.id);...
2
by: reap76 | last post by:
I am running the following query: if (select IntExternalAccountID from ExternalAccount) = (select IntExternalAccountID from InternalAccount) select * from InternalAccount where AccountPurpose=2 ...
0
by: fubaba | last post by:
hi, i execute a store procedure got Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.'...
13
by: ThePrinceIsRight | last post by:
I have a problem with using a subquery in MS Access. The purpose of the sub-query is to create a list of people who have had doctor exams in the past 6 months and exclude them from the main query....
1
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
3
by: jideesh | last post by:
---------------trigger code create trigger DeletepurchaseItems on table_purchaseitems for delete,update as begin select * from deleted update table_STOCK set ostock=(ostock-(select sqty from...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.