Results 1 to 4 of 4

Thread: ช่วยทีค่า เรื่องการตัดข้อมูลซ้ำโดยใช้ distinct

  1. #1
    Senior Member
    Join Date
    Jul 2007
    Location
    Bangkok
    Posts
    271


    ตารางเลขที่
    เลขที่บ้าน1 เลขที่บ้าน2
    1 2
    2 2
    3 4
    4 6
    3 5

    ต้องการ query ออกมาโดย ตัดตัวที่ซ้ำทิ้งไป
    ให้เป็นแบบนี้

    เลขที่บ้านรวม
    1
    2
    3
    4
    5
    6


    ไม่ทราบว่าทำไงได้บ้างคะ

    เราลอง
    SELECT DISTINCT Test5.Field2, Test5.Field1
    FROM Test5;

    แต่ข้อมูลมันออกมา2 ฟิลแบบนี้

    เลขที่บ้าน1 เลขที่บ้าน2
    1 2
    2 4
    3 5
    4 6


    วันนี้นั่งหาทั้งวันตั้งแต่เช้า จนป่านนี้....ยังคิดไม่ออกเลยง่าค่ะ

  2. #2
    Jedi Global Moderator
    Join Date
    Aug 2007
    Location
    Bangkok
    Posts
    136


    Table : Home
    N1 N2
    1 2
    2 2
    3 4
    4 6
    3 5

    select N1 AS N from `home`
    union(
    select N2 AS N from `home`)
    order by N;

    ได้เป็น
    N
    1
    2
    3
    4
    5
    6
    ถ้ากรณีที่มี ข้อมูลซ้ำ ให้ใช้ distinct ซ้ำอีกที โดยกำหนด Select ข้างบน เป็น Sub Query ครับ

  3. #3
    Senior Member
    Join Date
    Jul 2007
    Location
    Bangkok
    Posts
    271


    ขอบคุณมากๆเลยค่าทำได้แล้ว T-T

  4. #4


    ลองแบบนี้ดูนะครับ


    select num
    from
    (select field1 as num
    from t1
    union all
    select field2 as num
    from t2)
    group by num

Similar Threads

  1. Select Distinct In DATA TABLE
    By JamBoe in forum Visual Basic
    Replies: 0
    Last Post: 18-01-2007, 11:21 AM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •