2 Replies - 1008 Views - Last Post: 28 December 2011 - 10:48 PM Rate Topic: -----

#1 khaledkamal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-December 11

how to join 2 rows in query of sql server without repeating the row

Posted 20 December 2011 - 04:11 PM

how to join 2 rows in database by sql server
i made it by this code put it repete the same row
SELECT name,education_level,name_school,phone_home,mobile_student,mobile_home,addrees,name_pay,name_sbj
FROM students
 
FULL JOIN subjects
ON students.number =subjects.number

FULL JOIN payment
oN students.id_pay=payment.id_pay

where id_s=0


Is This A Good Question/Topic? 0
  • +

Replies To: how to join 2 rows in query of sql server without repeating the row

#2 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 782
  • View blog
  • Posts: 1,664
  • Joined: 30-January 09

Re: how to join 2 rows in query of sql server without repeating the row

Posted 20 December 2011 - 06:19 PM

Well, you're joining three tables there, and you're using FULL JOIN, which is the same as a LEFT and RIGHT JOIN at once. So, there's probably going to be a lot of rows returned that you're not after.

I'm not sure exactly what you require, but try this out:
SELECT
	name,
	education_level,
	name_school,
	phone_home,
	mobile_student,
	mobile_home,
	addrees,
	name_pay,
	name_sbj
FROM students
INNER JOIN subjects ON students.number =subjects.number
LEFT OUTER JOIN payment ON students.id_pay=payment.id_pay
WHERE id_s=0


This will generate a result set for all students that are in at least one subject, regardless of whether they have paid or not. Is that what you need?
Was This Post Helpful? 0
  • +
  • -

#3 pnev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-February 10

Re: how to join 2 rows in query of sql server without repeating the row

Posted 28 December 2011 - 10:48 PM

I agree with Euler. LEFT JOIN or RIGHT JOIN is what you're looking for.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1