473,322 Members | 1,431 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,322 software developers and data experts.

selecting rows not within another table

I have 2 tables Stores and Store_Projects that im trying to pull all
stores not in certian projects but belong to a customer. Heres the
design of each

CREATE TABLE `Stores` (
`storeID` int(10) unsigned NOT NULL auto_increment,
`storeMetro` int(11) NOT NULL default '0',
`storeManager` int(10) unsigned NOT NULL default '0',
`storeState` int(10) unsigned NOT NULL default '0',
`storeAddress` varchar(100) default NULL,
`storeCity` varchar(50) default NULL,
`storeZipcode` varchar(20) default NULL,
`storePhone` varchar(20) default NULL,
`projectStatus` varchar(20) default NULL,
`storeSupervisorName` varchar(100) default NULL,
`storeSupervisorPhone` varchar(20) default NULL,
`storeSupervisorEmail` varchar(255) default NULL,
`storeOtherContactName` varchar(100) default NULL,
`storeOtherContactPhone` varchar(20) default NULL,
`storeOtherContactEmail` varchar(255) default NULL,
`storeNumber` varchar(50) default NULL,
PRIMARY KEY (`storeID`),
UNIQUE KEY `storeID` (`storeID`),
KEY `storeMetro` (`storeMetro`)
)

CREATE TABLE `Store_Projects` (
`projectID` int(6) unsigned zerofill NOT NULL default '000000',
`storeID` int(11) NOT NULL default '0',
`billRate` varchar(10) NOT NULL default '0.0',
`associatePayRate` varchar(10) NOT NULL default '',
`repsNeeded` smallint(6) default NULL,
`storeServiceDateDay` smallint(2) unsigned default NULL,
`storeServiceDateMonth` smallint(2) unsigned default NULL,
`storeServiceDateYear` int(4) default NULL,
`receivedPayment` enum('Y','N') NOT NULL default 'N',
`invoiceNumber` varchar(25) default NULL,
`invoiceDate` date default NULL,
PRIMARY KEY (`projectID`,`storeID`)
)

I had designed the query like this

SELECT st.*, s.stateInitials, m.metroName, sta.stateInitials AS
metroState
FROM Stores AS st
LEFT OUTER JOIN CustomerUsers AS cu
ON cu.userID = st.storeManager
INNER JOIN States AS s
ON st.storeState = s.stateID
INNER JOIN MetroAreas AS m
ON st.storeMetro = m.metroID
INNER JOIN States AS sta
ON m.stateID = sta.stateID
INNER JOIN Store_Projects AS sp
ON sp.storeID = st.storeID
WHERE st.customerID = 4
AND sp.projectID != 000002

But of course thats not going to work if the store is not in the
Store_Projects table which it wouldnt be if its not in a specific
project. So I need a way to pull all Stores with a specific customerID
but is NOT in the Store_Projects with a specific projectID.

Can anyone explain how this should be done within the query? I could
do it by creating an array and then processing out all the stores but
I would much rather let MySQL do the work for figuring this out. Any
help would be greately appreciated.
Jul 19 '05 #1
0 1807

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

Similar topics

0
by: Chris N | last post by:
I have 2 tables Stores and Store_Projects that im trying to pull all stores not in certian projects but belong to a customer. Heres the design of each CREATE TABLE `Stores` ( `storeID` int(10)...
1
by: M Wells | last post by:
Hi All, Sorry if the subject line is too obscure -- I couldn't think of a way of describing this request. I have a table that contains approximately 1 million records. I want to be able to...
2
by: Robert | last post by:
Hi All, I'm trying to solve this for a few days now and I just can't figure it out... I have three tables set up, I'll simplify them for this question: Table 1: HOTELS Columns: HOTEL_ID,...
4
by: remote89 | last post by:
Hi experts, I have been trying to limit the table rows in the following situation, any suggestions will be appreciated. we have table called tempTb has columns id, c_id, c_name, rating, date...
4
by: Lucius | last post by:
Hello everyone, I have a query problem. I'll put it like this. There is a 'publishers' table, and there is a 'titles' table. Publishers publish titles (of course). Now I want to make a query (in...
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I...
1
by: Jay | last post by:
Hi All, My users are complaining about the page refreshing when they are selecting multiple rows in a datagrid. Has anyone tried to manage this using javascript? I tried smartnavigation but that...
1
by: Andy | last post by:
Hi Gang I have a simple single table that has many duplicate rows in them. The distinctrows only works on more than one table. Is there a quick and easy way to select only the distict rows...
7
by: USBZ0r | last post by:
Hi there guys! Im struggling to find a way to select all rows from a MySQL table that were edited within the last 2 minuites. When the user edits their profile, it time stamps it. So all i need to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.