This tag will generally be used by those unfamiliar with SQL, asking basic questions about joins. In SQL, data is stored in tables. Frequently, queries need data from multiple tables, and the way that they are connected may not be obvious.
Questions tagged [multiple-tables]
823 questions
3
votes
1 answer
Inheritance approach: STI? MTI? or simple polymorphic association?
I'm implementing an app to manage prodution orders. Each order has many processes (stages), including printing and bending. All processes have some common attributes as quantity and comments, and some stage-specific ones:
create_table :stages do…

Daniel Estrada
- 926
- 8
- 9
3
votes
2 answers
Select data from multiple tables with relations
You have all been great help in the past and I'm struggling with something so I have a question.
I have 3 tables in my SQL databas called 'Child', 'Parents' and 'Family'. The structure for the tables is shown below.
Here is some example data in the…

Naqash Tanzeel
- 103
- 2
- 8
3
votes
3 answers
How to combine 3 queries into one
I have 3 queries that ultimately get me daily financial information. What i'd like to do is combine the columns I need as 1 input. I tried doing derived tables but it is extremely sloppy and didn't work. Does anyone have any suggestion on how I…

Shmewnix
- 1,553
- 10
- 32
- 66
3
votes
3 answers
Sql SELECT for personnel available in a specific time period
I have 3 tables. First one is a list of personnel:
Table Personnel
Id_personnel Name
1 John
2 Alice
3 Tom
4 Charles
5 Ben
Second is a table with…

Mugur Ungureanu
- 161
- 1
- 11
3
votes
4 answers
Left Joining Three tables with Subquery
Check this fiddle for DB and tables
SELECT p.*
FROM Products p
LEFT JOIN offertran ot
ON p.prod_id = ot.prod_id
LEFT JOIN Offers o
ON ot.offer_id = (SELECT id FROM Offers
Where dF<=3 AND dt>=3)
ORDER BY o.id DESC,
…

Anusha
- 175
- 3
- 20
3
votes
4 answers
Select total of childrens in multiple tables in one query with mysql
All my afternoon was consumed trying to deal with a query (or two or three) in order to get the count of all childs of three tables. Take a look to my design:
user table
id_user | name
1 | foo
2 | bar
wons table
id_won | user
1 | 1
2 | 1
3 |…

manix
- 14,537
- 11
- 70
- 107
3
votes
2 answers
thousands of db tables VS one huge table
I am trying to develop an application that keeps track of daily stock data. (Each day a new record is created for every stock). There will be around 5000-10000 stock tracked. Then I need to analyze every day, month or other period some stock data,…

Lior Graf
- 163
- 1
- 10
3
votes
2 answers
how to query two tables and return NULL if a record is not in the 2nd table in MySQL?
I'm running MySQL 5.0.88 and need to select data from two tables, called articles and media.
When uploading images to my server I need to query all articles of a user and see whether there is already a path specified in the media table (field…

frequent
- 27,643
- 59
- 181
- 333
3
votes
1 answer
Android: How to use UriMatcher to switch multiple tables, query parametes and activities?
I would like to read your thoughts on how to solve the following problem. Here are the basic requirements of the application I am working on.
Display multiple locations one city on a map.
Support for multiple cities.
Display the properties of a…

JJD
- 50,076
- 60
- 203
- 339
3
votes
2 answers
fetch images from multiple mysql tables using php
I've been trying for the last couple of days to try and understand how to fetch data from multiple tables, but I cant say that I fully understood how it works. Anyway :)
What I am trying to do is to fetch the images stored in multiple tables using…

ekptwtos
- 101
- 2
- 11
3
votes
1 answer
Ruby on Rails - Where clause in multiple tables
Using rails 3.2.3.
This is driving me crazy. I know that active record is supposed to simplify these types of actions but I can't get my head around it.
I have a Hotel and Facility model. Both have a has_and_belongs_to_many relation.
A hotel can…

Silver
- 693
- 1
- 10
- 27
3
votes
4 answers
Select from table if exists, else select from a totally different table
I have a query to fetch two values:
string query = @"SELECT price, weight
FROM map
WHERE width = @width AND height = @height LIMIT 1";
if (_connSource.State != ConnectionState.Open)
…

nawfal
- 70,104
- 56
- 326
- 368
2
votes
1 answer
MySQL Left join AND second select for count
I have the following tables:
pages:
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
|…

Ivan Dokov
- 4,013
- 6
- 24
- 36
2
votes
1 answer
Group on ID, and sum from different table (3 table total)
I have three tables,
Name - columns
Custpackingslipjour(table 1) - (deliverydate, dateclosed,, salesid)
Inventrans (Table 2) - (itemid, datephysical, transrefid)
Salesline (Table 3) - (lineamount, itemid, salesid
What i need is a single table…

Tommy
- 91
- 1
- 14
2
votes
1 answer
Deleting multiple tables from SQL Server 2008 using Datalist C#
This may seem a common question but I googled to find the right answer that can fix my problem and failed to do so.
I have multiple tables connected to each other by ProductID and I wish to delete all data from them when the product from main table…

Ali Khan
- 91
- 3
- 10