0

Possible Duplicate:
Simple SQL Select from 2 Tables (What is a Join?)

Can I bound another sql data source to only one column in gridview.

Shortly, there is a gridview which includes 3 columns.

I want to add one more column and show a different value while using another sql sentence.

Is it possible?

In order to explain easily, I write an example..

Name     |  Gender   |  Year
-------------------------------
AAA      |     M     |  1990 
-------------------------------
BBB      |     F     |  1991 

These values come from one sql sentence.

Name     |  Tasks  | Gender   |  Year
--------------------------------------
AAA      |    20   |   M      |  1990 
--------------------------------------
BBB      |    2    |   F     |  1991 

"Tasks" column will come from another sql sentence.

I want to count tasks which one employee have. So I use count(*), but when I use it, I could not get another columns...

This subject is different from join.

Community
  • 1
  • 1
Stack User
  • 1,378
  • 5
  • 19
  • 40

2 Answers2

1

Try this:

SELECT a.Name,COUNT(*) as Tasks, a.Gender, a.Year 
FROM TableA a
JOIN TableB b ON a.Name = b.Name 
group by a.Name, a.Gender, a.Year 
Joe G Joseph
  • 23,518
  • 5
  • 56
  • 58
0

You may want to use a join statement like so:

SELECT a.Name, a.Gender, a.Year, b.New
FROM TableA a
JOIN TableB b ON a.Name = b.Name 

(I may have messed up MySQL syntax, though, I'm coming from a different database world...)

fjdumont
  • 1,517
  • 1
  • 9
  • 22