• Home
  • About

Snippet IT

IT News, Programming, Internet and Blogging

  • Programming and Scripting
  • Tips and Tricks
  • Software and Hardware
  • New and Happening
You are here: Home / Programming and Scripting / SQL: How To Select Data With Same Values On Columns

SQL: How To Select Data With Same Values On Columns

September 19, 2013 by Sze Hau Leave a Comment

Let say you have the following data in you database table t1 and you want to select the IDs for the row record that have the same value on COL1 and COL2.

ID   COL1   COL2   COL3
======================
1    100    200    300
2    200    300    400
3    100    200    500
4    300    300    300
5    200    300    400


And the expected result is ID = 1,2,3,5. The SQL to achive the result is:

select 
    left.ID
from
    t1 left inner join t1 right
on
    left.COL1 = right.COL1 and
    left.COL2 = right.COL2 and
    left.ID <> right.ID


You can also use “group by” then “count(*)” method but it is a bit more complicated and slow.

Filed Under: Programming and Scripting, Tips and Tricks Tagged With: SQL

About Sze Hau

Geek. Love programming. Coffee addicted. Married with two children. Working towards financial freedom.

Leave a ReplyCancel reply

Advertisement

Email News Letter

Sign up to receive updates daily and to hear what's going on with us

Software and Hardware

MD5 and SHA1 Checksum Using Windows

July 5, 2017 By Sze Hau Leave a Comment

Blog Network

  • Personal Fincance Personal Finance – Personal Money Tips, Stock Investment, Small Business and Make Money Online
  • szehau's weblog Life, Internet, Software, Gadgets, Programming and Investments

Snippet IT

This is the place where I want to share anything about information technology.

Search

Recent

  • MD5 and SHA1 Checksum Using Windows
  • MD5 and SHA1 Checksum Using Linux
  • Java: Unlimited Strength Jurisdiction Policy
  • WordPress: How To Change Admin Username
  • Linux: How To Compress And Decompress Folders And Files

Tags

advertisement blog C# Chrome DecimalFormat EGPC Float format format Integer free icons Gmail Google Google Adsense Google Chrome Google Search Engine Google search result how to HTTP Java JavaScript Linux money password performance PHP programming search engine optimization secure security short URL site value spam SQL static constructor String thread tiny URL Tips and Tricks trackback twitter video Wordpress wordpress plugin wordpress theme Youtube

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in