Jump to content

awjudd

Staff Alumni
  • Posts

    422
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by awjudd

  1. By two different DB for sure, do you mean two separate tables?

     

    Something like this should do:

     

    Student ( StudentID INT PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50), ... )
    StudentSick ( StudentID INT, SickDay DATETIME, IsValidated BOOL )

     

    SELECT s.FirstName, s.LastName, CASE ss.IsValidated WHEN 1 THEN 'Yes' ELSE 'No' END AS Validated
    FROM Student s
    JOIN StudentSick ss ON s.StudentID = ss.StudentID
    WHERE ss.SickDay >= DATE_SUB(NOW(), INTERVAL 48 HOUR)
    

     

    ~juddster

  2. You are going to need to define what you want to do more.

     

    You could be doing this limitation in the PHP side of your application.

     

    If you really want to do it in SQL you could probably do something like this:

     

    SELECT *
    FROM table2
    WHERE ( SELECT credits FROM table1 ) > 0
    

     

    ~juddster

  3. Why is this separated out into separate tables?  It looks to me that they could all be stored in one table and add in an extra column which is the news type (i.e. sports, international, local).  Then you would just be doing a query on one table ...

     

    Otherwise you would likely want to UNION each of the selects together.

     

    ~juddster

  4. Why are you doing an INNER JOIN on everything except for the LEFT JOIN on the Enrol table?

     

    If there is no match from the LEFT JOIN none of the other rows will be returned because the join condition will not be satisfied.

     

    i.e. if a student isn't enrolled in any classes then they will not appear in the ending result set (which is different than how you originally had your query).

     

    ~juddster

  5. There is no limitation on the number of tables which can be joined nor any limitations for INNER JOIN.

     

    If anything, something else in your query is wrong which is why for starters I pointed out the k.Birthday = '0000-00-00' AND k.Birthday BETWEEN ...

     

    When you add KidsStudent to the query does the query fail or just return no results?  Depending on which it is it points to two completely different issues.  That said, with my previous query we have proven that the relationship between Student and KidsStudent exists and will cause the data set being returned to be reduced but not empty (i.e. the JOIN isn't failing).

     

    ~juddster

  6. Two reasons why I doubt that the query you are providing is the one that you are running and is returning data:

    - Your Student table or your KidsStudent table contain a field called 'CourseName' and 'LessonStart' - unlikely because those are course level information (i.e. likely to be coming from c.Course in your previous query)

    - You are GROUPing BY 1 field and then applying no aggregation on the rest of them - this should cause an error because it doesn't make any sense

     

    This query should return information:

    SELECT FirstName, LastName
    FROM Student s
    JOIN KidsStudent k ON s.StudentID = k.StudentID
    GROUP BY FirstName, LastName
    

     

    ~juddster

  7. How can the same field have two values at one time?

     

    WHERE k.DateOfBirth = '0000-00-00' AND (k.DateOfBirth BETWEEN '1995-12-31' AND '2001-01-01')

     

    You are checking where it is empty (i.e. '0000-00-00) AND it is between 1995 AND 2001.

     

    ~juddster

  8. You are inserting into a mapping table so chances are you may not have that data in the application as of yet.

     

    INSERT INTO Territories ( RepID, PrincipalID, StateID )
         SELECT ( SELECT RepID FROM Reps WHERE RepName = 'ARepName' ) AS RepID
             , ( SELECT PrincipalID FROM Principals WHERE PrincipalName = 'APrincipalName' ) AS PrincipalID
             , ( SELECT StateID FROM States WHERE StateAbbreviation LIKE '%LA%' ) AS StateID
    

     

    Assuming they all return 1 row.  If they don't then you will need a bit more for the query to get it to work.

     

    ~juddster

  9. Solution 1:

    - Create a table that has ProductId, ImagePath.

    - Cycle through all images within your folder and INSERT the values into the previously created table

    - Run a join against the table you are checking for

     

    Solution 2:

    - Cycle through all products in your database checking in the images folder if there is an image

    - If there isn't then display it

     

    ~juddster

  10. Do you have any records in your KidsStudent table for any of the people within the Student table?

     

    The fact that you are referencing the same column twice makes no difference in the query.  What happens when you remove your WHERE clause?  Do you get results?

     

    ~juddster

  11. Do a LEFT JOIN onto the table where the person has the signatures ... For example (no fields were given, so I am making the fields up):

     

    SELECT *
    FROM ttmautos a
    LEFT JOIN 90toppstraded b ON a.AutoID = b.AutoID

     

    This will retrieve every row in the ttmautos table and either NULL if there is no matching row in the 90toppstraded table OR the row from that table where there is the match.

     

    Hope this helps.

     

    ~juddster

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.