Jump to content

SQL SELECT troubles...


eggie

Recommended Posts

I'll be direct, below is the problem I am having. I tried to explain it as best as I can. If I missed something, please let me know. This has been trying my patiences and I have a feeling there is an easy solution, but for the life of me I can't figure it out.Description of what's what and coming from where:A = cat_a from categoryA Space 888-555-1234 = bname and btel from directoryGolfer = cat from cateforyWorking code, but not in the order I am trying to output:

mySQL = "SELECT category.idcat, directory.idcat, cat, cat_a, bactive, bname, btel FROM category, directory WHERE bactive=-1 AND category.idcat=directory.idcat ORDER BY cat_a, bname ASC"

A Art Group 888-555-1234 Architects AT Pages 888-555-1234 Advertising Barthrop 888-555-1234 Attorneys Brackett 888-555-1234Gardener _____________________________________________________________________________Working code, but only half of what I need to output

mySQL = "SELECT bname, btel FROM directory WHERE bactive=-1 ORDER BY bname ASC"

A Space 888-555-1234 A Center 888-555-1234 A Clinic 888-555-1234etc... to Z's _____________________________________________________________________________The other half:

mySQL = "SELECT cat_a, cat FROM category ORDER BY cat_a"

ABCetc... to Z_____________________________________________________________________________What I am trying to do is combine

mySQL = "SELECT bname, btel FROM directory WHERE bactive=-1 ORDER BY bname ASC"

mySQL = "SELECT cat_a, cat FROM category ORDER BY cat_a"

To output:AA Space 888-555-1234Golfer A Center 888-555-1234Sailor A Clinic 888-555-1234TennisBB Space 888-555-1234Groomer B Center 888-555-1234Trainer B Clinic 888-555-1234AutoCC Space 888-555-1234 PlummerC Center 888-555-1234 PlanterC Clinic 888-555-1234Stemmeretc... to Z_____________________________________________________________________________So I try this:

mySQL = "SELECT bname, btel, cat_a FROM directory, category WHERE bactive=-1 ORDER BY bname ASC, cat_a"

I get page can not be displayed. HTTP500

Link to comment
Share on other sites

Hi.. May I have full table structure of those both tables.. I have also try like this: category: cat_a,cat directory: bname,btel SELECT c.cat, concat(d.bname,' ',d.btel) FROM `cat` AS `c` inner join directory as `d` on c.id = d.cat_id order by cat asc Suppose this will help u..Regards,Vijay

Link to comment
Share on other sites

Hi eggieYou appear to be trying to construct an index from a table called directory with headings taken from table category. which contains both headings and letters of the alphabet.If you are trying to do that, you need 3 select statements which you can UNION together. As the fields selected have different names you have to rename it using AS.Lets call the output field MYLISTTry something likeSELECT cat_a FROM category AS mylistUNIONSELECT cat FROM category AS mylistUNIONSELECT concat (bname,' ',btel) FROM directory AS mylist As all the fields as probably char or varchar you shouldn't need any conversion.Hope this helps - if not - post the table structures and required output as vijay suggested. The required output is important as I'm not convinced that I understand what you are trying to do.regardsnibe

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...