Thread: Help with SQL query
Results 1 to 2 of 2
Related
-
help with mysql query Forum: Databases
Replies: 2 -
MySQL query Forum: PHP Forum
Replies: 1 -
query Forum: HTML Forum
Replies: 1 -
IE div height query Forum: CSS Forum
Replies: 5 -
My sql query Forum: PHP Forum
Replies: 0
-
01-06-2010, 08:54 PM #1
Help with SQL query
Hello All,
Wondering if this is possible...
I have two tables
table 1
T1Col1
1
2
3
table 2
col1 col2
-1 4
2 5
-1 6
I need to show this
T1Col1 col2
1 4
2 4
3 4
1 6
2 6
3 6
so basically I need a record for each row in table one
for each value in table2 where col1=-1
I can't use cursors - looking for straight sql statement.
Right now I'm planning on building the sql in php and
using "union" to put them all together but was wondering
if there is a straight sql way to accomplish this.
Thanks!
-
02-14-2010, 08:26 PM #2
Re: Help with SQL query
A Cartesion join will work [see note at end]:
Select T1.T1Col1, T2.col2
from T1, T2
Where
--no join predicate ->> produces a cartesian product
T2.Col1 = -1
Order by T2.col2, T1.T1Col1;
Note: this will work ONLY if [per your example] 4 and 6 appear only once each in T2.col2 [a unique column].
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum