الانتقال إلى المحتوى

Make A Select


miro_feps

Recommended Posts



Dear all

I have two columns in al table its data is like the following


example :


stuff description

desk is red with glass
desk is rounded
desk having four legs
chair its color is brown




this is how the data in the table

what i want is to select from the column stuff the thing with the different description for it without repeating this stuff


such as the following :

desk is red with glass
is rounded
having four legs


chair its color is brown



Will you help me in that select please as fast as possiple thnks alot



رابط هذا التعليق
شارك

السلام عليكم...
هذا الحل ولكن النتائج سوف تظهر على الشكل التالي:

desk
is red with glass
is rounded
having four legs

chair
its color is brown

select Mixed from ( select distinct(stuff) Mixed,stuff,'1' from TableName union
select description,stuff,'2' from TableName order by 2,3)
/
رابط هذا التعليق
شارك

شكراً لك أخي الكريم,
بالنسبة لعبارة الـ Order by 2,3 يقصد بها بشكل عام الترتيب حسب الحقل الثاني الوارد في تعليمة الاستعلام فإذا تكررت هذه القيمة سيتم الترتيب حسي الحقل الثالث .
لتوضيح عمل التعليمة سنضع نتائج الاجتماع مباشرة كالتالي :

1  select distinct(job) Mixed,job,'1' Num from emp 2  union
 3  select ename,job,'2' from emp 4* order by 2,3
SQL> /
MIXED      JOB       N
---------- --------- -
ANALYST    ANALYST   1
FORD       ANALYST   2
SCOTT      ANALYST   2
CLERK      CLERK     1
ADAMS      CLERK     2
JAMES      CLERK     2
MILLER     CLERK     2
SMITH      CLERK     2
MANAGER    MANAGER   1
BLAKE      MANAGER   2
CLARK      MANAGER   2

MIXED      JOB       N
---------- --------- -
JONES      MANAGER   2
PRESIDENT  PRESIDENT 1
KING       PRESIDENT 2
SALESMAN   SALESMAN  1
ALLEN      SALESMAN  2
MARTIN SALESMAN  2
TURNER     SALESMAN  2
WARD       SALESMAN  2

19 rows selected.



لقد اضطررت إلى وضع الحقل الثالث من أجل ترتيب النتائج ,
فمثلاً بالنسبة للوظيفة ANALYST

ANALYST ANALYST 1
FORD ANALYST 2
SCOTT ANALYST 2

بهذه الحالة استطعت التحكم بوضع اسم الوظيفة في مقدمة أسماء الموظفين التابعين لها .
وسيتم الترتيب على حسب اسم الوظيفة فإذا تشابهت مع أحد الحقول الأخرى
ANALYST ANALYST 1
سيتم الترتيب حسب الحقل الثالث و هو الحقل الرقمي و بذلك أضمن توضع اسم الوظيفة في أول قائمة الموظفين .

تم تعديل بواسطة TROYMAN
رابط هذا التعليق
شارك

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   تمت استعادة المحتوى السابق الخاص بك.   مسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

جاري التحميل
×
×
  • أضف...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية