-
Posts
422 -
Joined
-
Last visited
-
Days Won
1
Everything posted by awjudd
-
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
-
Join your all students against your sick students? Please provide table definitions. It'll make it a lot clearer. ~juddster
-
We need more information and it all depends on your table structure. Please do not try to be generic in your posts. It just ends up biting you in the ass because nobody can help without any information. ~juddster
-
SELECT picnum, filename FROM filelist f LEFT JOIN tags t ON f.picnum = t.picnum WHERE t.picnum IS NULL ~juddster
-
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
-
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
-
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
-
What is the value of $SUBMIT_QUERY (i.e. what is emitted)? And no that doesn't matter/ ~juddster
-
And what does $SUBMIT_QUERY become? What does it do when you run it in phpmyadmin? You still have your $AGE_TO and $AGE_FROM swapped in your between clause. ~juddster
-
Post the source for your PHP page you are running this on. Or better yet, run this in phpMyAdmin and then you'll get a better sense of what is going on. ~juddster
-
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
-
how to set up the table structure to do date ranges searches?
awjudd replied to GridCube's topic in MySQL Help
Since you are storing all of the date information (day, month, year) I would use a DATE column (http://dev.mysql.com/doc/refman/5.0/en/datetime.html) instead of breaking it out into 3 separate. This will open you up to use the built in DATE functions in mysql (http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html). Hope this helps. ~juddster -
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
-
But the value can't be '0000-00-00' AND between '1995-12-31' AND '2001-01-01'. It could be '0000-00-00' OR between '1995-12-31' AND '2001-01-01'. ~juddster
-
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
-
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
-
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
-
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
-
Please mark the topic as resolved. ~juddster
-
That is a warning/notice and not an error. Did you do it for all of the $_POST variables? ~juddster
-
Please provide your table structure(s) if / how they relate. If they don't relate then it is the case of a simple UNION of 3 SELECT statements. ~juddster
-
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
-
It will allow us to not have to piece the query together ourselves based on guesses ... if you post the actual query that is. ~juddster
-
Destramic - didn't I already tell you this on IRC a week or two back that you can't conditionally join on stuff depending on stuff in your CASE statement? You need to either UNION the two queries together (i.e. one for Team tournaments and one for Singles tournaments) or alter your table structures so that they are all held in the same table (all tournaments). ~juddster
-
Something like this should work: SELECT SUM(MaxPrice) AS TotalPrice FROM ( SELECT MAX(Price) AS MaxPrice FROM mytable GROUP BY ItemNumber ) Basically running your max in the sub query and then based on those values, sum them up ~juddster