| Author |
Topic |
|
vasko102
Starting Member
6 Posts |
Posted - 2010-11-15 : 05:37:21
|
| Hi guys,I have problem with my query. I have 2 tables, table 1 looks like this:Table1 ID int,Name stringand Table2 looks like this:Table2ID int,table1_ID int, Value int My query should search for a record with some ID from table 2 but i wanna have all records from table 1 something like this:Select table1.Name, table2.Value From..... Where table2.ID = somethingName-----------------Value Something1------------1Something2------------3Something3------------16Something4------------0(Value is null)Something5------------0(Value is null)Something6------------7 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-15 : 05:44:54
|
| Hinttable1 left join table2MadhivananFailing to plan is Planning to fail |
 |
|
|
vasko102
Starting Member
6 Posts |
Posted - 2010-11-15 : 05:58:55
|
I know about the left join :) but the problem is that with left join i only get the columns where i have values. For exemple if i have this records in table 2:ID = 1, table1_ID = 1, Value = 100ID = 1, table1_ID = 2, Value = 3ID = 1, table1_ID = 3, Value = 16ID = 1, table1_ID = 6, Value = 7 I'll get only 4 records and i want to have 6 records and the result to be like this:Name-----------------Value Something1------------1Something2------------3Something3------------16Something4------------0(Value is null)Something5------------0(Value is null)Something6------------7quote: Originally posted by madhivanan Hinttable1 left join table2MadhivananFailing to plan is Planning to fail
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-15 : 06:03:36
|
| Post the code you usedMadhivananFailing to plan is Planning to fail |
 |
|
|
vasko102
Starting Member
6 Posts |
Posted - 2010-11-15 : 06:11:40
|
| SELECT P.Name, A.ValueFROM Table1 P LEFT JOIN Table2 a on P.ID= A.table1_ID where A.ID = 1 |
 |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2010-11-15 : 06:23:15
|
| u have to remove the where condition from your query.bcoz when you apply where condition the query engine looks for the matching records for the id that you pass in your where condition.in your query you have passed id=1 in the where clause, so you will be getting only the matching records with id=1 |
 |
|
|
vasko102
Starting Member
6 Posts |
Posted - 2010-11-15 : 06:32:12
|
but if i remove the where condition how can i get my result?quote: Originally posted by ahmeds08 u have to remove the where condition from your query.bcoz when you apply where condition the query engine looks for the matching records for the id that you pass in your where condition.in your query you have passed id=1 in the where clause, so you will be getting only the matching records with id=1
|
 |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2010-11-15 : 06:51:46
|
| when you want to get all the records whats the fun of passing where condition.you pass the where condition when you want to get the records for a particular id.just remove the where condition and check the query.is it giving all the records or not. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-15 : 07:37:35
|
| Instead of where use ANDMadhivananFailing to plan is Planning to fail |
 |
|
|
|