SQl Statement Need help with, please

  • THis is an SQL question - I have these problems that I hope you guys can help:

    For each band that has at least one event schedule, list the band number and name and number of events scheduled as  # Events Scheduled. Order by band name ascending

    create table band
    (bnd_id varchar(5) primary key,
    bnd_name varchar(50),
    bnd_street varchar(25),
    bnd_city varchar(20), 
    bnd_state varchar(20),
    bnd_zipcode varchar(10),
    bnd_phone char(20),
    bnd_type varchar(5),
    bnd_fee number,
    bnd_mgno varchar(4),

    create table event
    (evt_no varchar(5) primary key,
    evt_budget decimal,
    evt_bnd_id varchar(5),
    evt_venue_id varchar(5),
    Evt_date_time DATE,
    evt_duration number,
    evt_bus_id varchar(5),

    create table venue
    (ven_id varchar(5) primary key,
    ven_name varchar(50) ,
    ven_address varchar(50) ,
    ven_capacity varchar(50),
    ven_age_policy varchar(20));

    WHAT i HAVE BEEN DOING IS 

    SELECT bnd_id, bnd_name, evt_venue_id AS '#Events Schedule'
    FROM band, event
    OREDER By bnd_name;

    I tried this Join SQL and still not having luck, I need help, please

    SELECT band.bnd_id, event.evt_venue_id AS '#Events Schedule'
    FROM band INNER JOIN event ON band.bnd_id=b.evt_bnd_id;

  • mannyaluna - Friday, April 7, 2017 4:12 PM

    THis is an SQL question - I have these problems that I hope you guys can help:

    For each band that has at least one event schedule, list the band number and name and number of events scheduled as  # Events Scheduled. Order by band name ascending

    This sounds like homework.

    Show what you have tried, and we will show you why its not working

  • In addition to what you have tried so far, it also helps if you provide the table definitions in the form of CREATE TABLE statements, sample data in the form of INSERT INTO statements and the expected results based on that sample data.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • [/quote]

  • me thinks you need a join between "band" & "event" tables to start.....shouldn't be very difficult

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • mannyaluna - Friday, April 7, 2017 4:12 PM

    THis is an SQL question - I have these problems that I hope you guys can help:

    For each band that has at least one event schedule, list the band number and name and number of events scheduled as  # Events Scheduled. Order by band name ascending

    create table band
    (bnd_id varchar(5) primary key,
    bnd_name varchar(50),
    bnd_street varchar(25),
    bnd_city varchar(20), 
    bnd_state varchar(20),
    bnd_zipcode varchar(10),
    bnd_phone char(20),
    bnd_type varchar(5),
    bnd_fee number,
    bnd_mgno varchar(4),

    create table event
    (evt_no varchar(5) primary key,
    evt_budget decimal,
    evt_bnd_id varchar(5),
    evt_venue_id varchar(5),
    Evt_date_time DATE,
    evt_duration number,
    evt_bus_id varchar(5),

    create table venue
    (ven_id varchar(5) primary key,
    ven_name varchar(50) ,
    ven_address varchar(50) ,
    ven_capacity varchar(50),
    ven_age_policy varchar(20));

    WHAT i HAVE BEEN DOING IS 

    SELECT bnd_no, bnd_name, evt_venue_id AS '#Events Schedule'
    FROM band, event
    OREDER By bnd_name;

    1 - I would suggest giving some more thought to your data types.
    2 - You are selecting band_no in your query, but there is no band_no in any of your tables.
    3 - You need to research how to join tables. This is a starting point Types of Joins

  • DesNorton - Saturday, April 8, 2017 2:16 PM

    mannyaluna - Friday, April 7, 2017 4:12 PM

    THis is an SQL question - I have these problems that I hope you guys can help:

    For each band that has at least one event schedule, list the band number and name and number of events scheduled as  # Events Scheduled. Order by band name ascending

    create table band
    (bnd_id varchar(5) primary key,
    bnd_name varchar(50),
    bnd_street varchar(25),
    bnd_city varchar(20), 
    bnd_state varchar(20),
    bnd_zipcode varchar(10),
    bnd_phone char(20),
    bnd_type varchar(5),
    bnd_fee number,
    bnd_mgno varchar(4),

    create table event
    (evt_no varchar(5) primary key,
    evt_budget decimal,
    evt_bnd_id varchar(5),
    evt_venue_id varchar(5),
    Evt_date_time DATE,
    evt_duration number,
    evt_bus_id varchar(5),

    create table venue
    (ven_id varchar(5) primary key,
    ven_name varchar(50) ,
    ven_address varchar(50) ,
    ven_capacity varchar(50),
    ven_age_policy varchar(20));

    WHAT i HAVE BEEN DOING IS 

    SELECT bnd_no, bnd_name, evt_venue_id AS '#Events Schedule'
    FROM band, event
    OREDER By bnd_name;

    1 - I would suggest giving some more thought to your data types.
    2 - You are selecting band_no in your query, but there is no band_no in any of your tables.
    3 - You need to research how to join tables. This is a starting point Types of Joins

  • DesNorton - Saturday, April 8, 2017 2:16 PM

    mannyaluna - Friday, April 7, 2017 4:12 PM

    THis is an SQL question - I have these problems that I hope you guys can help:

    For each band that has at least one event schedule, list the band number and name and number of events scheduled as  # Events Scheduled. Order by band name ascending

    create table band
    (bnd_id varchar(5) primary key,
    bnd_name varchar(50),
    bnd_street varchar(25),
    bnd_city varchar(20), 
    bnd_state varchar(20),
    bnd_zipcode varchar(10),
    bnd_phone char(20),
    bnd_type varchar(5),
    bnd_fee number,
    bnd_mgno varchar(4),

    create table event
    (evt_no varchar(5) primary key,
    evt_budget decimal,
    evt_bnd_id varchar(5),
    evt_venue_id varchar(5),
    Evt_date_time DATE,
    evt_duration number,
    evt_bus_id varchar(5),

    create table venue
    (ven_id varchar(5) primary key,
    ven_name varchar(50) ,
    ven_address varchar(50) ,
    ven_capacity varchar(50),
    ven_age_policy varchar(20));

    WHAT i HAVE BEEN DOING IS 

    SELECT bnd_no, bnd_name, evt_venue_id AS '#Events Schedule'
    FROM band, event
    OREDER By bnd_name;

    1 - I would suggest giving some more thought to your data types.
    2 - You are selecting band_no in your query, but there is no band_no in any of your tables.
    3 - You need to research how to join tables. This is a starting point Types of Joins

    You are right, my bad, it was bnd_id, not no

    I thought it was a join, but which type?

  • mannyaluna - Saturday, April 8, 2017 2:45 PM

    You are right, my bad, it was bnd_id, not no

    I thought it was a join, but which type?

    Why don't you try each join type, and see what each one returns.

    Then when you have the data that you want, you can do some research on GROUP BY and COUNT

  • mannyaluna, I know this just homework, but if you plan to work in databases during your career, knowing the different types of joins is pretty important.  I'd also suggest that you read up on them.  Granted your homework won't get done any faster, but you'll learn something from it.

  • Ed Wagner - Sunday, April 9, 2017 6:46 AM

    mannyaluna, I know this just homework, but if you plan to work in databases during your career, knowing the different types of joins is pretty important.  I'd also suggest that you read up on them.  Granted your homework won't get done any faster, but you'll learn something from it.Ed

    Ed,

    I know that you are not aware of my age, and intentions, and for that matter, how I get to learn best (as you know, we all have different ways to acquire knowledge), some are book worms, some are visual and some are logical learners, that is why I never give suggestions or advice to anyone who I have no idea what their learning method is. I think you for your attempt, but, some times, the best help is no help at all, and keep our advice to ourselves; granted I am only saying based on your response to me, as I do not know you beyond your comment.

    FYI, I'm a 62 yr old student of life, always trying to learn more, and in this day of technology I choose to learn and not just go by old ways of doing things. I am learning, yes, this homework, but if you have a teacher that is more concern about the younger, work bound students, it is hard to get help, on the other hand, I have been the type that if you show me that this is done this way, and this is done this other way, I learn better.... I guess, I have been a more of a hands on, on the job learner, more than anything else.

    With having said done, I wish you well, and remember that every experience in life is either a win or a win.... never a loss.

    Best of luck to you.

  • mannyaluna - Saturday, April 8, 2017 2:45 PM

    You are right, my bad, it was bnd_id, not no

    I thought it was a join, but which type?

    I sent you an email explaining what was wrong with your query. below is a link to how joins work. It even has pictures... 🙂

    http://stackoverflow.com/questions/406294/left-join-vs-left-outer-join-in-sql-server

    MCSE SQL Server 2012\2014\2016

  • lkennedy76 - Sunday, April 9, 2017 5:05 PM

    mannyaluna - Saturday, April 8, 2017 2:45 PM

    You are right, my bad, it was bnd_id, not no

    I thought it was a join, but which type?

    THanks, and I just responded to your other email, I got the solution, which I posted up top.

    I sent you an email explaining what was wrong with your query. below is a link to how joins work. It even has pictures... 🙂

    http://stackoverflow.com/questions/406294/left-join-vs-left-outer-join-in-sql-server

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply