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
4
votes
2 answers
MySQL and faceted navigation (filter by attributes)
I feel like this question has probably been asked a thousand times already, so I apologize if it's been answered. And if so, can someone point me to the right posts/links?
What I'm trying to do is build a faceted navigation for my site. It uses…

Sridhar Balasubramanian
- 53
- 1
- 8
4
votes
4 answers
SHOW COLUMNS from multiple tables
I am trying to get the column names from 2 tables.
I tried a query like: (SHOW COLUMNS FROM users) UNION (SHOW COLUMNS FROM posts) but that does not work & returns a syntax error. I tried the same query using DESCRIBE but that did not work either.…

randomphp
- 233
- 2
- 4
- 14
4
votes
3 answers
INNER JOIN query using three tables to return Count and Sum of rows that match criteria
I am trying to join the data from three SQL tables.
The tables are in the following format:
clients
╔════════╗
║ CLIENT ║
╠════════╣
║ A ║
║ B ║
║ C ║
║ D ║
╚════════╝
work_times
╔════════╦══════════╦════════╦════════════╗
║…

Nick
- 4,304
- 15
- 69
- 108
4
votes
3 answers
Database design parent child table vs multiple tables
I am trying to create a parent child relationship for country-state-city-head. I considering two approaches-
1) Create a single table-
pk| name | type | parent
1 | US | country | …

blue01
- 2,035
- 2
- 23
- 38
3
votes
1 answer
MySQL - joining tables on same table multiple times with different conditions takes forever
Simplifying, I have four tables.
ref_TagGroup (top-level descriptive containers for various tags)
ref_Tag (tags with name and unique tagIDs)
ref_Product
ref_TagMap (TagID,Container,ContainerType)
A fifth table, ref_ProductFamily exists but is not…

OldSchool
- 41
- 4
3
votes
2 answers
One table for all users or separate table for each user in MySQL 10M records db
I am working on the website that could deal with 1000s of images for my clients. Say 20,000 files per user, circa 200 users (with hopes for 1000s soon).
Images are represented by vFile (unique id) records in MySQL InnoDB database describing…

Peeech
- 639
- 1
- 7
- 15
3
votes
3 answers
MySql: Select by Count with Union or Joins
I need a way for page moderators to view the members of their page ordered by the total number of posts the user has on that particular page. The posts are stored in different tables such as polls, downloads, wiki, etc (like 15 tables). Each of…

bowlerae
- 924
- 1
- 14
- 37
3
votes
2 answers
Left Join 2 tables on 1 table
It must be pretty easy, but i can't think of any solution nor can I find an answer somewhere...
I got the table 'users'
and one table 'blogs' (user_id, blogpost)
and one table 'messages' (user_id, message)
I'd like to have the following result: …

user993692
- 33
- 1
- 4
3
votes
5 answers
Using MAX with multiple tables
I have a four tables: products, pc, laptop, and printer.
Products(maker, model, type)
PC(code, model, speed, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type price)
What I need is to…

nathpilland
- 304
- 5
- 17
3
votes
3 answers
Insert into multiple table with jdbc
I am trying to use JDBC to insert into multiple tables. Because it has to be fast I want to use PreparedStatement and the executeBatch method. Tables are combinded by a foreign key relationship.
First idea was to use getGeneratedKeys() but this…

hans.g
- 149
- 3
- 7
3
votes
3 answers
Selecting distinct values from two tables
I have two rather large databases (+1 million rows each). Both tables have the same structure.
How can I check if each value in a column is unique across both tables?
Is there a
SELECT COUNT(DISTINCTcol) FROM tbl
type of query that will consider…

Tucker
- 7,017
- 9
- 37
- 55
3
votes
1 answer
Autocomplete from multiple tables
I'm wondering what is the most efficient way to obtain autocomplete results from multiple tables?
The caveat being; I want to be able to identify from what table the records are coming.
For example, given these example tables:
+- People
+- id
…

Dan Lugg
- 20,192
- 19
- 110
- 174
3
votes
1 answer
mySQL - Multiple rows into one row
I need data from multiple tables using joins. Below are the tables.
table 1 : list_vehicles
pk_vehicle_id vehicle_reg_no vehicle_type
1 REG1 Bus
2 1 Bus
7 1 …

Jigna Jain
- 255
- 2
- 13
3
votes
2 answers
Fetch multiple rows using max()
I have written the below query which gives me the resultant set -
select
a.character_name,
b.planet_name,
sum(b.departure - b.arrival) AS screen_time
from characters a
inner join timetable b
on a.character_name =…

SirAlex
- 33
- 3
3
votes
4 answers
Joining 3 tables and retrieve all the records from all the tables
I am joining three tables (performing a full outer join) so that I can retrieve all the records from all the tables. Problem that I am facing is with the order in which I join tables.
Table Information
alt text…

MOZILLA
- 5,862
- 14
- 53
- 59