dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: mysql. How do i select data from all records with the sama data?

  1. #1
    Join Date
    Jul 2013
    Posts
    112

    mysql. How do i select data from all records with the sama data?

    How can I select the name of all records where secondary_id = 2? "id" and "name" cant be used in the select

    id | secondary_id | name
    1 | 2 | James
    2 | 2 | Fred
    3 | 2 | Alice
    4 | 3 | Diana
    5 | 7 | Jerry
    6 | 2 | Emily
    ...
    etc.

    when doing a normal select, obviously only one of the records is selected, but i need all of the records with secondary_id = 2 to be selected
    Last edited by jag1; 08-10-2017 at 10:22 AM.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,783
    When doing a select based on a primary key field, of course you will only get one record. (What is a normal select?)
    When doing any query based upon any field you will get ALL of the records that have the field value that you desire. So just do it!

    PS - if you had tried it you would have already found this out.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,023
    Unless I'm missing something, sounds like you just need a simple where clause:
    Code:
    select * from table_name where secondary_id = 2
    ?
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles