yourguide Posted April 23, 2009 Share Posted April 23, 2009 Hi all... I have searched the forum, but I am either missing it or I don't understand enough to know how it applies to my situation so here goes. I have one table, just one. That table has product information in that includes spec data on each product. the columns are like "specalum", "specwatt", "specfoo", "specbar", etc. I want to return items that have spec data within ANY spec% column as long as that data is not empty like '' or 'N' since thats a flag meaning it doesn't apply to that product. what I have so far is: SELECT COLUMN_NAME FROM information_schema.`COLUMNS` C WHERE table_name = 'webitemmaster' AND COLUMN_NAME LIKE 'Spec%' ; Which gives me a list of all the "Spec%" columns.... now I need to somehow search within each of those columns in the list for any value that is NOT '' or 'N' I am new to SQL, so please bear with me... my table name is webitemmaster Could some kind soul please point me in the right direction. I think a select within a select is right, but I dont know exactly how to express it. Thank you so much for your time. Quote Link to comment Share on other sites More sharing options...
fenway Posted April 24, 2009 Share Posted April 24, 2009 Ignoring the obvious design flaw here, the issue is that you can't use a dynamic column list in sql Quote Link to comment Share on other sites More sharing options...
yourguide Posted April 29, 2009 Author Share Posted April 29, 2009 I realize this DB is not normalized.... but this is what I have to work with. I am a consultant and this is a small project... I suppose I can tell them I need to rewrite the daily dump of data so that its in a normal form.... but they just want it done ASAP. Thanks for your input. Quote Link to comment Share on other sites More sharing options...
fenway Posted April 29, 2009 Share Posted April 29, 2009 Then you need to issue two queries -- the one you already have, and then a second one following a php function that parses the info you get back from the schema. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.