An SQL join clause combines records from two or more tables or views.
1
vote
1answer
370 views
Select multiple columns in subquery
I am having trouble selecting all cloumns in a sub query and can't seem to get no where with joining for replacement.
http://sqlfiddle.com/#!2/2481e/1
The link is to the schema with my current ...
3
votes
1answer
73 views
Is there a standard way to replace codes with values from a lookup table for reporting or analytics?
Suppose I have a "main" table that was probably heavily normalized and consists largely of columns that merely contain codes that are lookups into other tables (they are probably foreign keys but feel ...
1
vote
1answer
161 views
Retrieving data from inner join using LIMIT and OFFSET
These are my two tables:
table1
qid[PK] |gid[PK] |abcd | xyz | date
---------------+---------+---------+------+------------
00001 | qwe | 54 | a | 1994-11-29
00002 ...
3
votes
1answer
336 views
Subqueries run very fast individually, but when joined are very slow
ypercube solved the problem. Subqueries were totally unnecessary, and the whole thing works with plain joins. It is still strange that MySQL's optimizer could not make use of my original query, ...
0
votes
1answer
153 views
Group By on column from joined table
its about the following query.
EXPLAIN SELECT phrase, infinitiv
FROM `dict_verbs_all` `t`
INNER JOIN `dict_verbs_all_language` `verbsGerman_c`
ON (`t`.`id`=`verbsGerman_c`.`verb_id`)
INNER JOIN ...
0
votes
2answers
169 views
Tuning query to remove joins for reporting
This is the query I was sent. There is currently no data in the system as I was converting this query from teradata to SQL server.
SELECT user_id FROM user_table
LEFT OUTER JOIN
(
SELECT user_id , ...
5
votes
2answers
91 views
mysql join by 2 ways - how it works? - which gives performance difference
I had 2 different ways to query the content which showed performance difference when executed..
The 1st way is
EXPLAIN select SOME_COLUMNS
from
( select *
from A
where CONDITION
) p
...
0
votes
2answers
61 views
Counting results for cross join
How I can get count results with cross join?
Example cross join:
SELECT t1.firstname, t2.lastname
FROM table1 t1 CROSS JOIN table1 t2
2
votes
3answers
788 views
How do I join two tables on two different instances of DB2?
There are two instances of DB2 running on the same machine. One has a table aliased to the a table in the other one. Is there a way to do this in DB2 or does it have to be done via an external tool?
...
4
votes
1answer
190 views
NEWID() In Joined Virtual Table Causes Unintended Cross Apply Behavior
My actual work query was an inner join, but this simple example with cross join seems to nearly always reproduce the problem.
SELECT *
FROM (
SELECT 1 UNION ALL
SELECT 2
) AA ( A )
CROSS JOIN ...
0
votes
2answers
193 views
Slow query with straight_join for small result
I have a performance-problem with a query in my application and I don’t understand the behavior of mysql.
The query consists of different joins, especially the join to the mentioncache-table. If the ...
-3
votes
3answers
411 views
Join tables on a partial string match
input: I have a table containing (any number of) user-supplied strings:
╔═══════╗
║ Value ║
╠═══════╣
║ To ║
║ An ║
╚═══════╝
And a table of user details:
╔════════╦══════════╗
║ UserID ║ ...
2
votes
2answers
85 views
Joining 4 tables and 2 counts
I have four tables.
UserMaster
----------
UserKey - PK
UserName
UserID - UNIQUE
UserLogTransaction
------------------
UserID - FK:UserMaster.UserID
LoginTime
LogoutTime
CallCenter
----------
...
1
vote
1answer
334 views
SQL Server: join two tables with “valid-to” dates
I have two tables like so:
T1_Key, T1_Data, T1_ValidUntil
1 A 2000-01-01
1 B 2000-06-30
2 C 2005-05-31
3 D 2004-12-31
3 E ...
20
votes
1answer
941 views
USING construct in JOIN clause can introduce optimization barriers in certain cases?
It was brought to my attention that the USING construct (instead of ON) in the FROM clause of SELECT queries might introduce optimization barriers in certain cases.
I mean this key word:
SELECT *
...
2
votes
1answer
77 views
JOIN 2 tables, and query data from them 3 times
Basically I have 2 tables: post_meta and posts.
post_meta has a post_id, key and value:
post_id key value
6343 make Chevy
6343 model Volt
6794 make Chevy
6794 model ...
3
votes
1answer
152 views
Complex SQL Query
I'm trying to formulate a single query to return a nice list of a host's interfaces and the interfaces attributes from the Cacti MySQL DB. Here are the tables I am referencing:
host_snmp_cache:
...
0
votes
0answers
111 views
Which update is faster using join or sequential?
My this question is in sequence of my previous question I asked.
I could write two solutions using Stored Procedure instead of trigger or nested-query .
Both use a helper function ...
2
votes
1answer
119 views
Update ranking on table
I have two tables:
mysql> desc rank ;
+----------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
...
2
votes
1answer
242 views
inner join on PK with extra criteria slow despite indices?
Given the two tables below I am struggling to understand:
why is the third query slow even though first two queries are fast
what exactly is EXPLAIN saying
can I do anything to significantly speed ...
4
votes
3answers
1k views
Optimizing query using view on EAV structure
An application is writing into a database that follows an EAV structure, similar to this:
CREATE TABLE item (
id INTEGER PRIMARY KEY,
description TEXT
);
CREATE TABLE item_attr (
item ...
3
votes
2answers
219 views
SQL ANSI JOIN precedence
I have a query that looks like this:
SELECT *
FROM TBLA A
LEFT JOIN TBLB B ON A.Col1 = B.Col2
RIGHT JOIN TBLC C ON B.Col3 = C.Col4
JOIN TBLD D ON C.Col5 = D.Col6
In which order ...
4
votes
3answers
174 views
Many-to-Too-Many Relationship
I'm working on a book database. And among others, I have the following two tables (a bit simplified for the question):
tblBook: ID, Title
tblPerson: ID, Name
Note that the tblPerson table contains ...
4
votes
2answers
464 views
Right Full Outer Join Query
I came across 1 query which is
Select * from R Natural Outer Join S
Where R=(A,B) has tuples {(1,2),(1,2),(3,4)} and S=(B,C) has tuples {(2,5),(2,5),(4,6),(7,10)}.
To implement this I created 2 ...
2
votes
4answers
3k views
Full Outer Join in MS Access
I have two staff lists:
List A:
StaffID Supervisor
====================
0001234 NULL
0001235 0001234
0001237 0001234
0001239 0001237
and
List B:
StaffID Supervisor
...
1
vote
0answers
133 views
Multi-Table Join to Single Destination
I am having a serious performance issue with join together four tables and placing the results (in a certain permutation) into one destination table. I am using MSSQL 2008 and good ole T-SQL.
To ...
2
votes
2answers
275 views
Select rows with repeat data within certain timeframe
As a follow-up question to my previous question on difficult row categorisation, I have another problem which I'm sure will be easily solvable. After this I plan on reading a good book or two on ...
1
vote
2answers
256 views
Count consecutive null rows from a joined table
I have the following tables:
members:
----------------------------------------------
| member_id | member_name | member_join_date |
----------------------------------------------
events:
...
1
vote
2answers
73 views
Efficiency for contact-contact relationships schema
I'm migrating data from a schema where people and organisations are separate tables to one where people and organisations are all treated as contacts (they share a lot in common). Currently, the ...
2
votes
3answers
640 views
Alternative query to this (avoid DISTINCT)
Note: I work with MSSQL 2008, but I guess it's valid for many others DB engines
I have this table "Users":
UserID User CountryID
1 user 1 1
2 user 2 2
3 user 3 3
4 user ...
1
vote
1answer
285 views
Unable to add records to query in Access 2007
I've found this excellent resource that covers why a query might be read-only. I have a query that is not read only, yet I'm unable to add new records to it.
There are three tables. Let's call them ...
2
votes
1answer
292 views
Should I use left join to do my job in this scenario?
What I want to do is to find out the items which appeared more than once in this table:
mysql> desc tables;
+-----------------+---------------------+------+-----+---------+-------+
| Field ...
0
votes
2answers
1k views
Joining two tables on multiple criteria
I have two tables products and positions.
products:
id BIGINT PRIMARY KEY,
product VARCHAR(100),
criterium1 VARCHAR(100),
criterium2 VARCHAR(100)
positions:
id BIGINT PRIMARY KEY,
position ...
3
votes
3answers
414 views
CROSS JOIN with temp table and CASE statement
I'm trying to CROSS JOIN a table with a view. Here is my code:
SELECT *
FROM ( SELECT * ,
CASE TypeId
WHEN 1 THEN InGs828S
WHEN ...
9
votes
2answers
1k views
SQL Server does not optimize parallel merge join on two equivalently partitioned tables
Apologies in advance for the very detailed question. I have included queries to generate a full data set for reproducing the problem, and I am running SQL Server 2012 on a 32-core machine. However, ...
1
vote
1answer
125 views
Querying multiple tables
I am working on a query from our ticketing system, and I am having problems figuring out the best way to join these tables together.
I have the following tables/fields:
SR_service: stores ticket ...
2
votes
2answers
104 views
Long JOINS Returns No result all tables have one to many relationship with a particular table [closed]
I have a Table Enterpries with Primary Key 'RCNO'. All other tables have a one to many relationship with Enterprise via it's RCNO column. I make a Join of all the tables and i get nothing. Below is ...
1
vote
2answers
395 views
In DB2, how can I disable NLJOIN?
I want to indicate to the optimizer, via SET or optimization profiles, that NLJOIN shouldn't be used at all when optimizing a query.
I've been looking for this for a while without any success. I ...
2
votes
5answers
528 views
Does 'Cities' deserve a separate table?
I have the following Customers table:
customer_id - int
company_name - nvarchar
street - nvarchar
city - nvarchar
comments - nvarchar
The app will only be used in part of one small country ...
3
votes
1answer
228 views
Build a three table join with a recusive table in the middle?
I have three relevent tables: Parts, PartGroup, and MarkupGroup.
Parts is simple.
PartID artificial primary key
Part part number
PartGroupID Foreign key
sample data:
1 ...
3
votes
1answer
1k views
how to fetch different data on compare rows of two tables
I have two tables in my database, one is user_app table in which user info are stored, table are as:
+--------------+--------------+------+-----+-------------------+-----------------------------+
| ...
0
votes
3answers
456 views
INNER JOIN making COUNT(*) slow
I have a very simple query:
SELECT COUNT(*)
FROM messages
INNER JOIN users ON messages.user_id = users.user_id
With the join it takes 1146 ms and without it takes 220 ms (220 ms still seems slow to ...
1
vote
1answer
243 views
Mysql Join to get multiple row value from
I am new to my Mysql and need help regarding join
I have a table called employee and this table contain some foreign key value like phone, address, sex. Table phone and address have 4 rows in it, I ...
0
votes
1answer
210 views
Slow performance of MySQL Join Query
I have inherited a site (running Coldfusion8 and MySQL 5.0.88) with a product search using multiple criteria. I'm struggling with optimizing the search, especially a pricelist check, which makes the ...
0
votes
3answers
161 views
Is adding rows better then adding columns in case their value is not consistent?
In my project I have a table of customers, each customer has his own special price for each product, It's a small business and there are currently about 5 products. The manager says there might be ...
1
vote
2answers
249 views
LIMIT a query Postgresql
im doing this query and it gives me multiple hits because of each assetid may contain many vb.title, how can i limit the result to only show 1 hit for each assetid?
'select DISTINCT v.id,
...
0
votes
1answer
1k views
How can I select the latest record having one state where no later records exist with any other state?
I want to select the last record (by datetime) having a given state where no later records exist with any other state for each given "widget".
widget state timestamp
------ ----- ...
2
votes
1answer
132 views
MySQL: Very slow query, not using index, no joins involved
I am running what I think is a very simple query:
SELECT SQL_NO_CACHE m.mbr_nbr
FROM tran.member m
WHERE m.cardnbr = 000099999930
The table member is a poorly written one, with 133 columns and ...
2
votes
1answer
294 views
Help with a complicated MySQL Query inserting data using select from 2 tables
I am stuck with a case and unable to get the desired result from my query..
I have to insert into a table some records based on multiple records from 2 different tables..
Tables: Target: ...
1
vote
2answers
458 views
Table orders regarding Nested loop join in DB2
First I would like to cite the existing post Table order in Join Query
so the author is saying that the table order really doesn't make things(result, access plan)different. I have doubt on this ...
