Jump to content


New Members
  • Posts

  • Joined

  • Last visited

Charp's Achievements


Newbie (1/5)



  1. LOL, I am reading you replies. Are you reading mine? I agreed that GROUP BY is not the answer. I do see your suggested methods but do not see how they can generate the desired output without checking values twice - once in mySQL (WHERE firstname = '') and then again in PHP ($row['firstname'] = ''). If I'm not following your replies it's not because I can't read. It's because my mySQL skills are rudimentary.
  2. I was just looking up GROUP BY and see that it's used with an aggregate function, so I think that's not going to work for me. Allow me to explain more thoroughly what I'm after. I'm trying to validate data from an uploaded CSV file. Errors could include missing values, like first and last names, or an invalid email address. I'm able to do this: $strQuery = "SELECT COUNT(CASE WHEN `firstname` = '' THEN 1 END) AS no_first, COUNT(CASE WHEN `lastname` = '' THEN 1 END) AS no_last, FROM tablename"; With the results, I can indicate that there are x rows with no first name and y rows with no last name, but it would be more useful for correcting the bad data in the CSV file if the report was something like this: No first name: rows 3, 11, 20 No last name: rows 1, 8, 11, 39 In other words, I would like to specify what is missing from any given row rather than just note that some rows are missing something.
  3. @requinix Yes, the distinction does matter. A simplified version of what I'm trying is do is to generate a report indicating which users (by ID) have no first name listed and which users (by ID) have no last name listed. Yes, some users may be in both lists. My thinking on GROUP BY is that the first group of rows would be those missing first names the the second group would be those missing last names. That thinking, however, may be off the mark. There's actually a number of checks I wish to perform, but If I can understand a simple example like the one I in my first post, I think I'll be able to extend that understanding to more complex examples.
  4. Hi All. I'm working to advance my understanding of mySQL and could use some pointers. I'm okay with basic queries such as: SELECT id, firstname FROM table WHERE firstname = ''; But I'm having a tough time wrapping my head around how I would combine the query above with the following: SELECT id, lastname FROM table WHERE lastname = ''; Is it possible to combine these queries into one such that I can output a list of IDs where firstname was empty and then a list of IDs where lastname was empty? It seems like GROUP BY should be used, but I'm getting no where with this on my own. BTW, I'm using PHP if that helps with providing any examples. Thanks in advance.
  • 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.