SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    stirling
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sql select where 2 names are the same

    Hi, is there anyone that knows a bit about php and can help me out?

    how do i number the selected values or can i use AS to give the ShortName string different values. At the moment it selects the same value for each shortname instead of taking one from each table.

    query2 = "SELECT Pictures.ShortName,Categories.ShortName FROM Stats,Pictures,Categories WHERE Pictures.CategoryNo = Categories.CategoryNo AND Stats.PictureNo != Pictures.PictureNo";
    :
    :
    while (rs2.next()) {
    String pic = rs2.getString("ShortName"); //both different
    String cat = rs2.getString("ShortName");
    out.println("<TR><TD>"+pic+"</TD><TD>"+cat+"</TD></TR>");
    }

  2. #2
    SitePoint Enthusiast ModestITExpert's Avatar
    Join Date
    Jun 2004
    Location
    Planet Earth
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    Hi,

    Modify your SQL query in the following way:
    Code:
    query2 = "
    SELECT
      Pictures.ShortName as PictShortName,
      Categories.ShortName as CatShortName
    FROM
      Stats,
      Pictures,
      Categories
    WHERE
      Pictures.CategoryNo = Categories.CategoryNo AND
      Stats.PictureNo != Pictures.PictureNo
    ";
    Hope this will help.

  3. #3
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try using an Alias in your SQL

    Code:
    SELECT Pictures.ShortName AS picshort, Categories.ShortName AS catshort, ...
    Then use those Alias' in the rest of your script.

    >EDIT > Just Beaten to it...


Bookmarks

Posting Permissions

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