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

sqlite conditional select from multiple tables

131 128KB
I've got 5 tables that are related; there are other fields in each table, but these are trouble makers.

Expand|Select|Wrap|Line Numbers
  1.    tbl_1
  2. vol_key TEXT(),
  3. fil_id INTEGER
  4. type INTEGER
  5.  
  6.    tbl_2
  7. vol_key TEXT(),
  8. fil_key INTEGER
  9.  
  10.    tbl_3 (type is 1)
  11. vol_key TEXT(),
  12. fil_key INTEGER
  13.  
  14.    tbl_4 (type is 2)
  15. vol_key TEXT(),
  16. fil_key INTEGER
  17.  
  18.    tbl_5 (type is 3)
  19. vol_key TEXT(),
  20. fil_key INTEGER
  21.  
right now, I've got the following

Expand|Select|Wrap|Line Numbers
  1. SELECT tbl_1.*, tbl_2.* FROM tbl_1,tbl_2
  2. WHERE
  3. (tbl_1.vol_key='some_string'
  4. AND
  5. (tbl_2.fil_key=tbl_1.fil_id
  6. AND
  7. tbl_2.vol_key='some string'))
The above seems to work to get results from tbl_1 and tbl_2, but I also need to add the data from tbl_3 through tbl_5 when tbl_1.type is a 1, 2, or 3. I tried the CASE WHEN, but got an error near "CASE" message.

My question is how would I code the conditional CASEs to pull in tbl_3 - tbl_5 if they're required while not breaking the query in tbl_1 and tbl_2 if the data from the latter tables aren't needed?

Expand|Select|Wrap|Line Numbers
  1. SELECT tbl_1.*, tbl_2.* FROM tbl_1, tbl_2,
  2. CASE WHEN tbl_1.type=1 THEN tbl_3.* END AS t_3,
  3. CASE WHEN tbl_1.type=2 THEN tbl_4.* END AS t_4,
  4. CASE WHEN tbl_1.type=3 THEN tbl_5.* END AS t_5
  5. FROM tbl_1, tbl_2 WHERE (...)
  6.  
I started with this, but it ended before it bagan with the error message near "CASE". I'm lost with this overly complicated exotic stuff. :D

Any ideas would be greatly appricated. TIA
Mar 14 '14 #1

✓ answered by Rabbit

Are the fields in the 3, 4, and 5 not the same type of data? If they aren't, then you should normalize your data and only have one table with the type as a field.
http://bytes.com/topic/access/insigh...ble-structures

If they are, then you need to outer join those tables.

2 1695
Rabbit
12,516 Expert Mod 8TB
Are the fields in the 3, 4, and 5 not the same type of data? If they aren't, then you should normalize your data and only have one table with the type as a field.
http://bytes.com/topic/access/insigh...ble-structures

If they are, then you need to outer join those tables.
Mar 14 '14 #2
divideby0
131 128KB
Thank you for the reply and the link.

I've saved the link and will mill over it to see which table method is best suited for what I'm trying to do.

The tables do share common data types such as the "keys" but also have different fields for details specific to graphics, audio, or video.
Mar 15 '14 #3

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

Similar topics

7
by: Guy Hocking | last post by:
Hi there, I have a problem in my ASP/SQL Server application i am developing, i hope you guys can help. I have a ASP form with list boxes populated by SQL tables. When a user selects a value...
4
by: jeff brubaker | last post by:
Hello, Currently we have a database, and it is our desire for it to be able to store millions of records. The data in the table can be divided up by client, and it stores nothing but about 7...
1
by: Ahmet Karaca | last post by:
Hi. myds.Reset(); mycommand.SelectCommand.CommandText= "Select att1 from Ing as Ingredient, Pro as Product "+ "where Pro.ad='apple' and Pro.id=Ing.id"; mycommand.Fill(myds, "Product"); // Here...
8
by: Jason L James | last post by:
Hi all, does anyone know if I can create a dataview from multiple datatables. My dataset is constructed from four separate tables and then the relationships are added that link the tables...
5
by: Craig G | last post by:
i was told that its possible to load more than 1 datatable into a dataset using a stored procedure i need to fill 3 combo's on my form if i had a SQL Stored Proc that had 3 different select...
13
by: ricky.agrawal | last post by:
I'm really not sure how to go about this in Access. What I've created is a table for each location. Those tables are identical in format but different in information. The tables are named after...
2
by: chopin | last post by:
I am using Microsoft Access, and VBA. I was wondering if it was possible to select multiple tables using DAO. For example, here is the code I am thinking should work, but doesn't: sSQL =...
4
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
2
by: danorourke99 | last post by:
Hi, In my Access database I have a table (dbo_000_DataCubeProcessing) which contains a list of tables that I need to export to Excel on a regular basis along with a checkbox for each. Once I...
3
by: DeanL | last post by:
Hi guys, Does anyone know of a way to create multiple tables using information stored in one table? I have a table with 4 columns (TableName, ColumnName, DataType, DataSize) and wanted to know...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.