Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. query to find engineering student

query to find engineering student

Scheduled Pinned Locked Moved Database
databasegame-devhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    srinandan
    wrote on last edited by
    #1

    I am having problem to build a query. I have following data in a table. NAME SUBJECT ------------------ sri physics sri chemistry sri math amit physics amit bio amit math sanjay Phsysics sanjay chemistry sanjay math Ritu physics Ritu Chemistry Ritu bio i need to find the name of student (engineering) who are studying physics, Chemistry and math. in above table output should be as follows: NAME -------- sri sanjay Can anyone tell the sql query. Thanks, Sri...

    N 1 Reply Last reply
    0
    • S srinandan

      I am having problem to build a query. I have following data in a table. NAME SUBJECT ------------------ sri physics sri chemistry sri math amit physics amit bio amit math sanjay Phsysics sanjay chemistry sanjay math Ritu physics Ritu Chemistry Ritu bio i need to find the name of student (engineering) who are studying physics, Chemistry and math. in above table output should be as follows: NAME -------- sri sanjay Can anyone tell the sql query. Thanks, Sri...

      N Offline
      N Offline
      Niladri_Biswas
      wrote on last edited by
      #2

      Try this

      declare @t table(name varchar(50),subject varchar(50))
      insert into @t
      select 'sri','physics' union all
      select 'sri','chemistry' union all
      select 'sri','maths' union all
      select 'amit','physics' union all
      select 'amit','bio' union all
      select 'amit','maths' union all
      select 'sanjay','physics' union all
      select 'sanjay','chemistry' union all
      select 'sanjay','maths' union all
      select 'Ritu','physics' union all
      select 'Ritu','chemistry' union all
      select 'Ritu','bio'

      select name from @t
      where subject ='maths' or subject ='physics' or subject ='chemistry'
      group by name
      having (COUNT(name)>2)

      Output:

      name

      sanjay
      sri

      :)

      Niladri Biswas

      S 1 Reply Last reply
      0
      • N Niladri_Biswas

        Try this

        declare @t table(name varchar(50),subject varchar(50))
        insert into @t
        select 'sri','physics' union all
        select 'sri','chemistry' union all
        select 'sri','maths' union all
        select 'amit','physics' union all
        select 'amit','bio' union all
        select 'amit','maths' union all
        select 'sanjay','physics' union all
        select 'sanjay','chemistry' union all
        select 'sanjay','maths' union all
        select 'Ritu','physics' union all
        select 'Ritu','chemistry' union all
        select 'Ritu','bio'

        select name from @t
        where subject ='maths' or subject ='physics' or subject ='chemistry'
        group by name
        having (COUNT(name)>2)

        Output:

        name

        sanjay
        sri

        :)

        Niladri Biswas

        S Offline
        S Offline
        srinandan
        wrote on last edited by
        #3

        Thanks Biswas, Its working fine Thanks, Sri...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups