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

Help with multiple tables SQL

Hi hope someone can help.

I have 3 tables, a location table (showing the id and name of each location), a product table (showing the id and name of each product) and a storeProducts table, showing which stores sell which products. I want to be able to display a list of all locations, plus another column (true/false) stating whether they appear in the storeProducts table for a specified product. I can obviously get a list of locations that appear in that table for product, say, 'p6':

SELECT location.locationID, location.locationName
FROM location INNER JOIN storeProducts ON location.locationID = storeProducts.locationID
WHERE (((storeProducts.productID)='p6'));

But I would like to display all the locations, and state whether they appear in the storeProducts table for product'p6'. Can anyone help?
Feb 17 '07 #1
1 1176
MMcCarthy
14,534 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. SELECT location.locationID, location.locationName,
  2. If (storeProducts.productID='p6') Then 'Yes' Else 'No' As InStore
  3. FROM location LEFT JOIN storeProducts 
  4. ON location.locationID = storeProducts.locationID
  5. WHERE (((storeProducts.productID)='p6'));
  6.  
Not 100% sure if the IF...ELSE syntax is correct for MySQL but worth a try.

Mary
Feb 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mike | last post by:
I am not a sql person and could use some help with a delete...here is what I want: I have the following tables/fields (only including necessary fields) answers result_id results result_id
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
12
by: chreo | last post by:
I GIVE UP...I can't refresh datagrid (dataset) I have datagrid = dgrPaczki Datasource of that datagrid = DataSetPaczki1.PACZKI_PAKOWALNIA (forgive me Polish words) Dataadapter which fills my...
1
by: crazdandconfusd | last post by:
I have a database with two tables I use for shipping information. One is for if I'm only shipping one item and the other is for a back page of a report for when I ship multiple items. If I'm...
5
by: odntuk | last post by:
Hello, I'm new to database development and need your help. Although, I'm new I know that storing multiple entries into a database field is a horrible idea. Therefore, I'm trying to implement...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
2
by: megann | last post by:
Hi, My name is Megan and I am 21 and just learning to use Access. I was hoping that someone would be able to help me. My problem is that I have created a database with multiple tables (over 10)...
3
by: castor. | last post by:
hi all, i have two tables BOOK ------------------------------------ CODE NOT NULL NUMBER TITLE VARCHAR2(45) YEAR NUMBER
16
by: Okonita via DBMonster.com | last post by:
Hi all, I am comming along with all this Linus/DB2/scripting business...I am no longer scared of it!! (LOL). But, I need to create a .ksh script that does a REORGCHK and output only tables...
6
by: nzkks | last post by:
Hi I am using these: ASP.Net 2.0 with VB.Net, Visual Studio 2005, SQL Server 2005 I suspect, there is something missing in BLL class. I created the ASP.Net form also and checked whether it is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.